Archive for the ‘UNIX’ Category

Essential DBA Unix

September 12th, 2011 No comments

Hi All,

I am listing the command which we are frequently used in our DBA unix enviorment. I would lile to thnx Abhay for sharing this.

Essential DBA Unix
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!System Administration!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

su : Acquiring super user status
su – henery : Crearting Other users (henery) environment
passwd : Changing Passowrd
date : Setting the system date
wall : Write message all users desktop , terminate
calender : display calender

Read more…

Performance Tuning – Scenario Based

January 13th, 2011 No comments

Scenario 1
If an application makes multiple statement and each statement calls to a specific stored procedure. Thereby, being a multithreaded application it will call stored procedure multiple times at a time. It has been noticed that for some calls procedure takes longer time for different set of parameters. What could be the issue?

Solution 1
First we can’t blame sqarely on stored procedure for the slower performance. We have few options here
1. Reduce the number of concurrent calls to stored procedure.
2. Check whether the procedure is calling any child procedure with input parameter or not. Suppose child procedure is looking for location and if parent procedure is passing location as an input parameter and while the absence of this input parameter child procedure might be processing all available locations, which could be in huge number, and consuming time. So before calling the child procedure, apply proper check which would reduce the time consumptions for remaining calls.

Unix – Bits & Pieces

December 31st, 2010 No comments

1. Single quotes protect all special characters except single quote
e.g. $echo ‘Hi, “ life is all about making sense out of non sense – By Sybanurag’
output – Hi, “ life is all about making sense out of non sense – By Sybanurag

2. Double quotes don’t protect double quotes and $ and `(backquote)
e.g. $echo “Hi, “ life is all about making sense out of non sense – By Sybanurag”
output — Hi, life is all about making sense out of non sense – By Sybanurag

3. Double quotes protect single quotes, and single quotes protect double quotes.

Process Basics
1. When two users run the same same program, there is one program on disk but two processes in memory.

Problem 1
Can a process be orphand?

Solution 1
Every process has a process, you can’t have an “orphaned” process, though a process can remain in orphaned state for a small moment.

Dot Matching
* and ? don’t match a filename starts with a dot.
* and ? don’t match the / in a pathname.

Character Class
[] is a character class.
The expression [a-zA-Z]* matches all filenames beginning with an alphabet, irrespective of case.
*.[!co] – Matches all filenames with a single-character extension but not the .c or .o files.
[!a-zA-Z]* Matches all files names that don’t begin with an alphabetic character.

cp $HOME/prog_sources/*.{c,java} — Copy all files in a directory having extension c or java
cp $HOME/source/{project, html}/* — Copy all files from the directories project and html

Categories: UNIX Tags:

Vi Editor – Part 3

December 30th, 2010 No comments

Problem 13
How to perform pattern search in vi editor?

Solution 13
open a file in vi editor in command mode then follow below commands..
/patn — searches forward for pattern patn. For e.g. to search for pattern “execute” use /execute
?patn — searches backward for pattern patn
n — repeat search in same direction along which previous search was made
N — repeat search in direction opposite to that along which previous search was made

Problem 14
how to substitute?

Solution 14
Use below..
:5,10s/x/y/g — Substitute every occurence of “x” by “y” from line 5 to 10
:.s/x/y/g — Substitute every occurence of “x” by “y” in the current line only
:$s/x/y/g — Substitute every occurence of “x” by “y” in the last line

If you need confirmatory substituion then use “c” with “g” like below

Note: Significance of “g” is to substitute every occurence in a line else first occurence of “x” will be replaced by “y” in every line only.

I am closing Vi Editor here for now. Hope this will help you all. Suggestions and Criticism are cordially welcomed and highly appreciated :-)..Enjoy learning

Categories: UNIX Tags:

Vi Editor – Part 2

December 29th, 2010 No comments

Problem 6
How to copy range of lines from a file to another?

Solution 6
Suppose i want to copy 50 lines from line number 15 to 64, then open file in vi editor in command mode then follow below command
:15,64w file2.txt

For single line –> :10w file2.txt
For current line where cursor is positioned –> : .w file2.txt
For last line –> :$w file2.txt
For current line to end –> : .,$w file2.txt

Problem 7
What are repeat factor and how to use in navigation?

Solution 7
k — move cursor up
j — move cursor down
h — move cursor left
l — move cursor right

if want to move 5 lines up then use “5k” this is called repeat factor.

Problem 8
how to navigate among words in a line?

Solution 8

Problem 9
How to do “copy and paste” in vi editor?

Solution 9
Open a file in vi editor in command mode,
y — copy single character
yy — copy current line
15yy — copy current line and 14 lines below

p – paste text on right
P – paste text on left

NOTE: p and P paste text on right and left when delete single character of line. However, same keys paste “below” and “above” when delete complete line.

Problem 10
How to join lines?

Solution 10
Use “J” in command mode. Additionally, if want to join current line and 5 lines below current line then use “6J” (called repeat factor)

Problem 11
How to discard all changes in a line before moving away from the line.

Solution 11
Use “U” in command mode

Problem 12
How to repeat last command?

Solution 12
Use “.” in command mode. For e.g. if you have deleted 3 lines using “3dd” then you can delete 3 lines again and again by pressing “.”

Categories: UNIX Tags:

Vi Editor – Part 1

December 28th, 2010 No comments

Basic Vi Editor commands
Problem 1
How to do the undo in Vi editor?

Solution 1
Go to command mode and press “u” to undo the last action.

Problem 2
How to convert lines into comments?

Solution 2
Use “I” and “A”
“I” inserts at the beginning of line.
“A” appends at the end of line.
So press “I” and type /* then [Escape] and then press “A” and type */ then [Escape]. Due to this each line can be converted to comment.

Problem 3
How to insert lines above and below the current line without placing the cursor at the start and end of line?

Solution 3
Use “o” and “O”
open a file in command mode and press “o” which inserts a new line below the current line.
Open a file in command mode and press “O” which inserts a new line above the current line.

Problem 4
What is the difference between s,S,r,R in command mode?

Solution 4
r –> Replaces a single character with one character.
R –> Replaces all text on the right of the cursor position.
s –> Replaces a single character with many.
S –> Replaces the entire line irrespective of cursor position.

Problem 5
How to save and quit in one character?

Solution 5
Use “:x” in command mode.

Categories: UNIX Tags:

Usage of #! /usr/bin/ksh..

August 11th, 2010 No comments

I came across with below article for the usgae of #!/usr/bin/ksh.

Just Sharing….

Source : www

Originally, we only had one shell on unix. When you asked to run a command, the shell would attempt to invoke one of the exec() system calls on it. It the command was an executable, the exec would succeed and the command would run. If the exec() failed, the shell would not give up, instead it would try to interpet the command file as if it were a shell script.
Then unix got more shells and the situation became confused. Most folks would write scripts in one shell and type commands in another. And each shell had differing rules for feeding scripts to an interpreter.
This is when the “#! /” trick was invented. The idea was to let the kernel’s exec() system calls succeed with shell scripts. When the kernel tries to exec() a file, it looks at the first 4 bytes which represent an integer called a magic number. This tells the kernel if it should try to run the file or not. So “#! /” was added to magic numbers that the kernel knows and it was extended to actually be able to run shell scripts by itself. But some people could not type “#! /”, they kept leaving the space out. So the kernel was exended a bit again to allow “#!/” to work as a special 3 byte magic number.
#! /usr/bin/ksh
now mean the same thing. I always use the former since at least some kernels might still exist that don’t understand the latter.
And note that the first line is a signal to the kernel, and not to the shell. What happens now is that when shells try to run scripts via exec() they just succeed. And we never stumble on their various fallback schemes.

– Senior Unix SA

Categories: UNIX Tags: , , , ,

Cleaning Shared Memory Segment and semaphore, for the ASE startup..

January 30th, 2010 2 comments

Panic dataserver, stopping it manually, and on restart showing issues with memory , meanwhile business people wants updates in every 5 mins…The situation is really worst for a DBA.

This posting is related to shared memory problem, for cleaning the shared memory:

When we shutdown the Sybase dataserver abruptly, by using the kill -9 or kill -12(or due to any reason automatically).

During the restart, sometime it gives the problem unable to create shared memory region, as below:

os_create_region: shmget (0x%x): %s

os_create_region: Shared memory segment %d is in the way

os_create_region: uninitialized shared memory descriptor

os_create_region: shmat (%d): %

Killing Process may left behind the System V semaphore or shared memory left behind instead of being cleaned up automatically. To eliminate unneeded semaphores or shared memory segments, we need to release semaphore or shared memory segment manually.

For the Semaphores:

Run the command ipcs -sa, it will give all semaphores active in the UNIX box, look for the value “0” in the column NSEMS. 0 values indicate that unused semaphore, find all semaphore for the Sybase user and remove them using command ipcrm -s

testinghostname:(/sybase)=>ipcs -sa
IPC status from as of Thu Sep 17 08:50:11 EST 2007
s 201326671 0xc103d804 –ra-ra-ra- patrol dba patrol dba 2 8:45:15 0:00:08
s 201326668 0xc103d80e –ra-ra-ra- sybase dba sybase dba 0 8:50:08 0:00:00

testinghostname:(/sybase)=>ipcrm -s 201326668

For the Shared Memory:

To cleanup the Shared memory segment, which are assigned at OS level but not in use, run ipcs -ma command.

testinghostname:(/sybase)=>ipcs -ma
IPC status from as of Thu Sep 17 08:50:24 EST 2007
Shared Memory:
m 654311446 0x4103d80e –rw-rw-rw- patrol dba patrol dba 0 2304 1766 1766 8:50:18 8:50:18 0:00:08
m 671088657 0x4103d80d –rw-rw-rw- sybase dba sybase dba 0 1792 1766 1762 8:45:15 8:45:15 0:00:08
m 671088650 0x4103d80b –rw-rw-rw- root root root root 0 768 1766 1766 8:50:18 8:50:18 0:00:08
m 671088648 0x4103d80a –rw-rw-rw- sybase dba sybase dba 1 1280 1766 1766 8:50:18 8:50:18 0:00:08
m 654311548 0x4103d809 –rw-rw-rw- sybase dba sybase dba 0 256 1766 1766 8:50:08 8:50:08 0:00:08

Now look in the NATTCH field for 0, if it 0 zero for Sybase user , it is unneeded, but still assigned at OS level. Remove it ipcrm -m by providing the id.

testinghostname:(/sybase)=>ipcrm -m 671088657 -m 654311548

Now Start the dataserver….

Same case with backup server, if u get any error with shared memory..!


Source : Sybooks and UNIX Manuals on wwww.
Same Thread @