1752552 Members
4425 Online
108788 Solutions
New Discussion

Scripting Help

 
Dadski
Advisor

Scripting Help

Hello,

 

I have a scripting query that maybe someone can help with.

 

for instance I have a file with the following output.

 

SVSA            Physloc                                      Client Partition ID
--------------- -------------------------------------------- ------------------
vhost19         U9119.595.837F98E-V1-C119                    0x00000009

VTD                   NO VIRTUAL TARGET DEVICE FOUND

SVSA            Physloc                                      Client Partition ID
--------------- -------------------------------------------- ------------------
vhost20         U9119.595.837F98E-V1-C120                    0x0000000a

VTD                   10r2510d.383205
Status                Available
LUN                   0x8100000000000000
Backing device        hdisk55
Physloc               U5791.001.99B0K01-P1-C05-T1-W5005076801306672-L2000000000000
Mirrored              false

 

I would like to run a script based on each vhost,  the script should (based on the individual vhost) be able to interrogate the disk for its size and format the output like so.

 

p10005vion22 hdisk12 33213600507680181858B780000000000025204214503 00c91efb3af8d0fb vhost6 0x00000009 0x8100000000000000

 

 

P.S. This thread has been moved from HP-UX>System Administration to HP-UX > languages. -HP Forum Moderator

 

 

 

4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: Scripting Help

>the script should (based on the individual vhost) be able to interrogate the disk for its size and format the output like so.

 

It would be helpful if your sample output fields matched your input file.

Also you mentioned query the disk for size, what commands would be used?

 

Where does the first field p10005vion22 come from?

2) is "Backing device".

3) is?

4) is?

5) is SVSA

6) is "Client Partition ID"?

7) is "LUN"

Dadski
Advisor

Re: Scripting Help

Firstly thanks for looking at this Dennis. 2. is the UUID and 3. is the PVID.

 

 

I had something like the following. To get the parameters but was hoping to loop against a vhost and output as.

 

 

  SERVER=`uname -n`
  IOS=/usr/ios/cli/ioscli
  DISK=`awk '/hdisk/{print $NF}'`
  UUID=`odmget CuAt|grep -wp ${NUM}|grep -p unique|awk -F"=" '/value/{print substr($2,3,55);}' | sed s'/ //;s/\"//'`
  PVID=`lspv|grep "${NUM} "|cut -c16-36`
  CLNTID=`awk '/vhost/{print $NF}'`
  LUNID=`awk '/LUN/{print $NF}'`
  print "${SERVER};${NUM};${UUID};${PVID};${VHOST};${CLNTID};${LUNID}" | sed 's/\;/ /g'

 

 

p10005vion22 hdisk12 33213600507680181858B780000000000025204214503 00c91efb3af8d0fb vhost6 0x00000009 0x8100000000000000

 

 

so I thought something like.

 

FILE=lsmap-ML
lsdev | awk '/vhost/{print $1}' > /home/martin/$FILE

 

for VHOST in `cat $FILE`
do

 

for VADAPTER in `$IOS lsmap -vadapter $VHOST

do

 

  SERVER=`uname -n`
  IOS=/usr/ios/cli/ioscli
  DISK=`awk '/hdisk/{print $NF}'`
  UUID=`odmget CuAt|grep -wp ${NUM}|grep -p unique|awk -F"=" '/value/{print substr($2,3,55);}' | sed s'/ //;s/\"//'`
  PVID=`lspv|grep "${NUM} "|cut -c16-36`
  CLNTID=`awk '/vhost/{print $NF}'`
  LUNID=`awk '/LUN/{print $NF}'`
  print "${SERVER};${NUM};${UUID};${PVID};${VHOST};${CLNTID};${LUNID}" | sed 's/\;/ /g'

 

done

done

 

or something like that

Dennis Handly
Acclaimed Contributor

Re: Scripting Help

>so I thought something like.

 

So what doesn't work?

 

>SERVER=`uname -n`

 

You should replace all uses of `` by $().

 

>DISK=`awk '/hdisk/{print $NF}'`

 

Your awk script has to read from a file, otherwise it's from stdin.  Is this your issue?

 

>| sed s'/ //;s/\"//'`

 

Why are you quoting the (")?

>print "${SERVER};${NUM};${UUID};${PVID};${VHOST};${CLNTID};${LUNID}" | sed 's/\;/ /g'

 

Why add semicolons then remove them?  Also no need to quote that semicolon.

 

>lsdev | awk '/vhost/{print $1}' > /home/martin/$FILE

>for VHOST in `cat $FILE`; do

 

You can combine:

for VHOST in $(lsdev | awk '/vhost/ {print $1}'); do

 

>for VADAPTER in

 

I don't see $VADAPTER used?

 

>UUID=`odmget CuAt | grep -wp ${NUM} | grep -p unique

 

There is no -p option to grep(1).

Dadski
Advisor

Re: Scripting Help

Hi Dennis, sorry for the delay.  I have the script functioning now, the only snag is, it falls over when a vhost has more than 1 disk.  This is it so far.

 

I was going to add an if statement for if the vhost has more than one disk then do this.  But its the formatting of it, I just cant get my head around :(   any help would be great. 

 

So if I run this on 3 vhosts,  1 with no disk and the others with one eqch,  i get this.

 

server1 vhost19 nodisk 0x00000009
server1 hdisk55 3321360050768018E8333700000000000025104214503IBMfcp  00c7f98ef2471312     vhost20 0x0000000a 0x8100000000000000
server1 hdisk63 3321360050768018E8333700000000000025904214503IBMfcp  00c7f98ef247135a     vhost21 0x0000000a 0x8100000000000000

 

#!/usr/bin/ksh

#mkdir -p /home/martin/
#touch /home/martin/lsmap-ML
FILE=/home/martin/lsmap-ML
#lsdev | awk '/vhost/{print $1}' > $FILE

for VHOST in `cat $FILE`
do
        IOS=/usr/ios/cli/ioscli
        SERVER=`uname -n`
        $IOS lsmap -vadapter ${VHOST} > ${FILE}.new
        DISK=`awk '/hdisk/{print $NF}' ${FILE}.new`
        if [[ -z  ${DISK}  ]]
        then
                CLNTID=`awk '/vhost/{print $NF}' ${FILE}.new`
                print "${SERVER};${VHOST};nodisk;${CLNTID}" | sed 's/\;/ /g'
        else
                for ALLDISK in `awk '/hdisk/{print $NF}' ${FILE}.new`
                do
                        UUID=`odmget CuAt|grep -wp ${ALLDISK}|grep -p unique|awk -F"=" '/value/{print substr($2,3,55);}' | sed s'/ //;s/\"//'`
                        PVID=`lspv|grep "${ALLDISK} "|cut -c16-36`
                        CLNTID=`awk '/vhost/{print $NF}' ${FILE}.new`
                        LUNID=`awk '/LUN/{print $NF}' ${FILE}.new`
                        print "${SERVER};${DISK};${UUID};${PVID};${VHOST};${CLNTID};${LUNID}" | sed 's/\;/ /g'
                done
        fi
done