SysAdmin Blog, TechTips and Reviews

An (ex) System Administrator's Blog

Archives Posts

How To Detach Mirror in Solaris – Script

April 13th, 2012 by elizar

How to detach mirror disks in Solaris? Assuming we us SVM, we normally do this like this, manually:

metastat -c d0 (verify disk components)
eeprom bood-device (further verify the boot disk)
metadetach rootdev detachdevice

or put it a script for repetitive use and to avoice typo mistakes:

cat detach_mirror.ksh

rootdev=`df -k /|tail -1|awk '{print $1}'|cut -d"/" -f5`
bootdisk=`eeprom boot-device|cut -d"=" -f2|awk '{print $1}'`

if [[ $bootdisk = "disk" || $bootdisk = "disk0" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t0d0"|awk '{print $1}'`
elif [[ $bootdisk = "disk1" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t1d0"|awk '{print $1}'`
elif [[ $bootdisk = "disk2" ]]; then
detachdev=`metastat -p $rootdev|tail -2|grep -v "t2d0"|awk '{print $1}'`
echo "Unknown disk to detach"

echo "boot-disk is $bootdisk"
echo "root device is $rootdev"
echo "\nmetastat -p $rootdev"
metastat -p $rootdev

echo "\ncommands:"
echo "sync; metadetach $rootdev $detachdev"
echo "sleep 10"

detachdiskname=`metastat -p $detachdev|awk '{print $NF}'`
echo "mkdir /a"
echo "mount /dev/dsk/$detachdiskname /a"
echo "cp -p /a/etc/vfstab /a/etc/"

#echo awk '$1=="/dev/md/dsk/'$rootdev'" {print "/dev/dsk/'$detachdiskname'\t/dev/rdsk/'$detachdiskname'\t"$3"\t"$4"\t"$5"\t"$6"\t"$7; next} {print}' /etc/vfstab
echo "awk '\$1==\"/dev/md/dsk/$rootdev\" {print \"/dev/dsk/$detachdiskname\\\t/dev/rdsk/$detachdiskname\\\t\"\$3\"\\\t\"\$4\"\\\t\"\$5\"\\\t\"\$6\"\\\t\"\$7; next} {print}' /etc/vfstab" \> /a/etc/vfstab
echo "egrep -v \"rootdev.*md|MDD root info\" /etc/system > /a/etc/system"

echo "\ncd /"
echo "umount /a"
echo "rmdir /a"

Filed under Script, Solaris having No Comments »

Archives Posts

KSH Script Basics | Special Shell Variables

April 23rd, 2010 by elizar

Just deleted tons of stale, unsused user accounts. Here are some KSH shell basics and special shell variable. I need to Google them up myself to get reminded that ‘$?’ is the output variable for script execution. That is, it’s 0 for successful execution and 1 if there is any error.

Read the rest of this entry »

Archives Posts

UNIX One-Liners: Some Useful Shell Programs

May 23rd, 2009 by elizar

My Favorite One-Liners: Some Useful Shell Programs… But first things first… I would like to note that this aint my list of favorite shell programs.. well, it has become… but what I mean is this aint an original article that I created and posted here.. this is a section from the now defunt, Sysadmin Magazine… and you’ll be reading a lot of those here….

“Keep It Simple, SysAdmin,” or perhaps just “Keep It Shell Script”, that is one of the motto that every sysdamin knows… They automate, they script, they relax.

Too many system administrators, especially former or frustrated programmers, get involved and distracted creating ad hoc programs that grow until they have a life and a following of their own. These programs generally are written in C, awk, or C shell, have no documentation, and are incomprehensible, even to the author, less than two weeks after being finished.

Read the rest of this entry »

Archives Posts

Searching For Fee Car Classifieds Script

April 30th, 2009 by elizar

Cars are no longer a luxury nowadays (except if you want to own a Ferrari or something). Cars are now a necessity in today’s standard of living. And let’s face it, with the price of brand new cars and the forever raising price of gasoline, not every one can buy a new set of wheels.

Thanks to websites that offer to sell (and buy) second hand, used cars many people can have places to search for and are no longer limited to the restrictions of locations.

I bought my first car (my only car for that matter) from a dealer that posted their inventory online. So, thanks to this second hand used car website, I was able to find myself and buy my very own car.

Read the rest of this entry »

I was here...