Author Topic: My afternoon in a nutshell:  (Read 307 times)

Offline drax0r

  • Major FANTASTIC Member
  • *******
  • Posts: 3433
  • Muckraker Extraordinaire
    • Anna Texas Community Forum
My afternoon in a nutshell:
« on: December 11, 2009, 04:29:59 PM »
I came up with a simple, elegant, one-line solution to a problem.  This solution fixed 98% of cases it was meant to address.

The solution for the other 2% involved 40 lines of code and for loops nested 3 levels deep:

#!/usr/bin/ksh

SP="www.xxx.yyy.zzz"
SCRIPT=$(basename $0)
SOURCE=/var/adm/scripts/SnapView
DATA=$SOURCE/data

if [[ -z $1 ]]
then
  echo "###############################################"
  echo "## No SID specified, exiting."
  echo "## Example: $SCRIPT dev1 "
  echo "###############################################"
  exit 1
fi

SID=$1

OUTPUT_FILE=$DATA/${SID}_recreate.txt
HDISK_LIST=`powermt display dev=all | grep Pseudo | awk -F"=" '{print $2}'`

cp /dev/null $OUTPUT_FILE

for VG in `cat $DATA/${SID}_vg_to_lun_map.txt | awk '{print $1}'`
do
        HDISK=""
        for LUN in `grep $VG $DATA/${SID}_vg_to_lun_map.txt | awk '{$1=""}1'|sed 's/^ //'`
        do
                UID=`naviseccli -h $SP getlun $LUN | grep UID | tr -d ":" | awk '{print $2}'`
                        for x in $HDISK_LIST
                        do powermt display dev=$x | grep $UID > /dev/null && HDISK="$HDISK $x"
                        done
        done
        echo $VG $HDISK >> $OUTPUT_FILE
done
Everything I say, do, imply, or infer is the sole representation and responsibility of the individual who owns this account and does not represent the opinion, policy, position, or intent of any organization or other entity, public or private.

Offline Family Guy

  • Hero Member
  • *****
  • Posts: 684
Re: My afternoon in a nutshell:
« Reply #1 on: December 11, 2009, 04:44:20 PM »
 ???

Offline ehowton

  • Colonel COURAGEOUS Member
  • *********
  • Posts: 7595
  • Fingering the Muse
    • http://ehowton.livejournal.com
Re: My afternoon in a nutshell:
« Reply #2 on: December 11, 2009, 04:46:30 PM »
Impressive as always.  Depending on the output of your first awk statement might be modified to run on HP/UX, but since you're using volume groups (assuming AIX) that'll translate nicely.  Timely too, since Steve accidentally mapped the $18,000-per-drive SSD array last week and had to work double-quick to get everything moved before end-of-month disk reports came out and they charged us for those capacity-on-demand drives.

P.S.  Why doesn't it look like a Christmas tree?

Offline drax0r

  • Major FANTASTIC Member
  • *******
  • Posts: 3433
  • Muckraker Extraordinaire
    • Anna Texas Community Forum
Re: My afternoon in a nutshell:
« Reply #3 on: December 11, 2009, 04:55:38 PM »
Impressive as always.  Depending on the output of your first awk statement might be modified to run on HP/UX, but since you're using volume groups (assuming AIX) that'll translate nicely.  Timely too, since Steve accidentally mapped the $18,000-per-drive SSD array last week and had to work double-quick to get everything moved before end-of-month disk reports came out and they charged us for those capacity-on-demand drives.

P.S.  Why doesn't it look like a Christmas tree?

Larry Wall, author of Perl, once said "It's easier to port a shell than a shell script."

I've been working on re-purposing ~600 lines of ksh that I wrote 6 years ago for Solaris to AIX.  I think he might be right.


Tell Steve I just got done writing some scripts to use the native LVM tools to do live migrations from one backend lun to another.  I'll port it to HP-UX and implement it for ~$17,000 per drive.
Everything I say, do, imply, or infer is the sole representation and responsibility of the individual who owns this account and does not represent the opinion, policy, position, or intent of any organization or other entity, public or private.