Tuesday, July 24, 2012

Shell Scripting

1. To remove all the empty lines in a file
            #grep -v "^$" testfile where testfile - filename

^ - means beginning of the line
$ - end of the line
           
Above characters are called anchors . 

One more example : 

grep -i  ^ts testfile

Which will display the line which has "ts" in the beginning of the lines


Usage of sed:

Deleting all the lines matching a particular pattern:

Take the vfstab file where you want to delete all the lines containing tmpfs

#sed /tmpfs/d vfstab

Where d indicates delete all the lines matching pattern tmpfs
similarly p means print. Lets do one exercise.

I want to print only the ufs filesystem specified in vfstab file

#sed -n /ufs/p vfstab

Where -n option is used to print only those lines matching the pattern else all lines will be displayed.

There are few operators which are commonly used

p - print
d - delete
g - global - which means operation is performed on all the occurrence of the pattern.
s - substitute

All other operators, i believe is self explanatory.
 


# echo "suman mandal" | sed 's/\([a-z]*\) \([a-z]*\)/\2 \1/'

Output of the above command will
mandal suman




Shell Scripting

1. To remove all the empty lines in a file
            #grep -v "^$" testfile where testfile - filename

^ - means beginning of the line
$ - end of the line
           
Above characters are called anchors . 

One more example : 

grep -i  ^ts testfile

Which will display the line which has "ts" in the beginning of the lines


Usage of sed:

Deleting all the lines matching a particular pattern:

Take the vfstab file where you want to delete all the lines containing tmpfs

#sed /tmpfs/d vfstab

Where d indicates delete all the lines matching pattern tmpfs
similarly p means print. Lets do one exercise.

I want to print only the ufs filesystem specified in vfstab file

#sed -n /ufs/p vfstab

Where -n option is used to print only those lines matching the pattern else all lines will be displayed.

There are few operators which are commonly used

p - print
d - delete
g - global - which means operation is performed on all the occurrence of the pattern.
s - substitute

All other operators, i believe is self explanatory.
 


# echo "suman mandal" | sed 's/\([a-z]*\) \([a-z]*\)/\2 \1/'

Output of the above command will
mandal suman

vxprint -g oracle -dF "%publen" | awk 'BEGIN {s = 0} {s += $1} END {print s/2097152, "GB"}'


Sunday, July 22, 2012

Veritas Volume Manager- Important handy commands

1. Unable to import diskgroup:

Their may be many reasons for which you may not be able to import the diskgroup however the diskgroup shows clean in vxdisk -o alldgs list

One common reason is the diskgroup was not deported cleanly . Use the below commands to fix the issue

#vxdg -f -C import appdg -- which will clean up the existing host id and import the diskgroup


2. A quick way to check which are the volumes in a diskgroup have been started


#vxinfo -g


# vxinfo -g datadg
datavol        fsgen    Startable



In the above output, the last field "startable" means volume is fine can be started by the following commands


# vxvol -g datadg start datavol
# vxinfo -g datadg
datavol        fsgen    Started
#




Using vxprint also you can also get the status of the volumes



#vxprint -qhtg




Below steps are used for SAN migration. Its very simple.


Attaching a plex:

# vxplex -g appdg att appvol appvol-01

Removing a plex:

-- If above looks good, then go ahead & detach old plex
# vxmend -g testdg off oradata9-01
# vxplex -g testdg dis oradata9-01

remove the plex

# vxedit -g -rf rm   --- delete the plex

remove the disk from diskgroup

# vxdg -g appdg rmdisk disk01





Forcibly starting a disabled volume:

# vxvol -g mydg -o bg -f start myvol

Clearing the failing flag on a disk

Failing flag could be because of many reasons such as intermittent I/O error which could be because of temporary removal of a cable, controller fault, partially faulty LUN in the array.

#vxedit set failing=off mydg02

 





 







Veritas Volume Manager- Important handy commands

1. Unable to import diskgroup:

Their may be many reasons for which you may not be able to import the diskgroup however the diskgroup shows clean in vxdisk -o alldgs list

One common reason is the diskgroup was not deported cleanly . Use the below commands to fix the issue

#vxdg -f -C import appdg -- which will clean up the existing host id and import the diskgroup


2. A quick way to check which are the volumes in a diskgroup have been started


#vxinfo -g


# vxinfo -g datadg
datavol        fsgen    Startable



In the above output, the last field "startable" means volume is fine can be started by the following commands


# vxvol -g datadg start datavol
# vxinfo -g datadg
datavol        fsgen    Started
#




Using vxprint also you can also get the status of the volumes



#vxprint -qhtg




Below steps are used for SAN migration. Its very simple.


Attaching a plex:

# vxplex -g appdg att appvol appvol-01

Removing a plex:

-- If above looks good, then go ahead & detach old plex
# vxmend -g testdg off oradata9-01
# vxplex -g testdg dis oradata9-01

remove the plex

# vxedit -g -rf rm   --- delete the plex

remove the disk from diskgroup

# vxdg -g appdg rmdisk disk01





Forcibly starting a disabled volume:

# vxvol -g mydg -o bg -f start myvol

Clearing the failing flag on a disk

Failing flag could be because of many reasons such as intermittent I/O error which could be because of temporary removal of a cable, controller fault, partially faulty LUN in the array.

#vxedit set failing=off mydg02

 





 







Wednesday, July 4, 2012

Solaris Zones

Below are some commands  to find processes related to zones.

ps -efZ - Display all processes along with the corresponding zone name
ps –fz my-zone1 - Display all process associated with a zone

Resource management for a running zone

To set the swap memory to 600MB

prctl -n zone.max-swap -v 600m -t privileged -r -e deny -i zone zone1

To set the physical memory to 500MB

rcapadm -z my-zone1 -m 600m

Where zone1 is the zone name.



Solaris Zones

Below are some commands  to find processes related to zones.

ps -efZ - Display all processes along with the corresponding zone name
ps –fz my-zone1 - Display all process associated with a zone

Resource management for a running zone

To set the swap memory to 600MB

prctl -n zone.max-swap -v 600m -t privileged -r -e deny -i zone zone1

To set the physical memory to 500MB

rcapadm -z my-zone1 -m 600m

Where zone1 is the zone name.