1833129 Members
4032 Online
110051 Solutions
New Discussion

Help with script

 
SOLVED
Go to solution
GTownes
Advisor

Help with script

Hi All,

Super novice at scripting looking for a little guidance. Trying to figure out how to get the lun wwn and first device file for the lun with awk. This is is what I get when I run the following command.

sudo autopath display | egrep -i 'lun wwn |/dev/dsk' | awk '{print $0}'

Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0775-0000
/dev/dsk/c19t0d6 Active
/dev/dsk/c21t0d6 Active
/dev/dsk/c23t0d6 Active
/dev/dsk/c25t0d6 Active
/dev/dsk/c27t0d6 Active
/dev/dsk/c29t0d6 Active
/dev/dsk/c31t0d6 Active
/dev/dsk/c33t0d6 Active



How can I pull just the lun wwn and first device file ?
10 REPLIES 10
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help with script

Hi:

To get the lun (line) and first device file you could do:

# sudo autopath display | awk 'NR==1 {LINE=$0};NR==2 {LINE=LINE" "$1};END{print LINE}'

Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0775-0000 /dev/dsk/c19t0d6

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Help with script

Hi (again):

Actually, since I can't tell from your data whether or not 'autopath display' outputs more than that which you have shown, it would be better to do:

# sudo autopath display | awk '/^Lun WWN/ {LINE=$0;getline;LINE=LINE" "$1};END{print LINE}'

Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0775-0000 /dev/dsk/c19t0d6

Regards!

...JRF...
GTownes
Advisor

Re: Help with script

Jeff,

Wasn't sure if all the line information was needed. Here's a full line section for a single lun.

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0737-0000
Virtual Device File : /hpap/dsk/hpap16
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d1 Active
/dev/dsk/c21t0d1 Active
/dev/dsk/c23t0d1 Active
/dev/dsk/c25t0d1 Active
/dev/dsk/c27t0d1 Active
/dev/dsk/c29t0d1 Active
/dev/dsk/c31t0d1 Active
/dev/dsk/c33t0d1 Active

==================================================================



I ran both commands, the first one just returns the dotted lines, and the second one just comes back to command prompt.
James R. Ferguson
Acclaimed Contributor

Re: Help with script

Hi:

...and that's a good reason to provide not only the output you want but to offer the raw _input_. Try this:

# sudo autopath display | awk '/^Lun WWN/ {LINE=$0};/^\/dev/ {LINE=LINE" "$1;print LINE;exit}'
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0737-0000 /dev/dsk/c19t0d1

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: Help with script

The way I read the question you'd like the first (active??) device for each Lun reported on.

So then you do not want the exit, but you do want to stop printing after a first dev line.

Try this for an awk command:

awk '/^Lun WWN/ {LINE=$0};/^\/dev/&&LINE {print LINE, $1;LINE=""}'

So if the scripts see a line starting with 'Lun', then that line is remember in variable line.

Next, if a line starts with 'dev' AND there is something true in that variable LINE, then print LINE and the first field, and clear LINE making it false.

Enjoy,
Hein.

GTownes
Advisor

Re: Help with script

Guys, thanks for awesome responses. However, perhaps I'm doing something wrong. I'm still getting just a return prompt with no output.

I'm trying to get it to return the Lun WWN and the first device name. Here's the entire list set of luns from autopath display. I would like to just pull the Lun WWN and the first device name for each lun.

sudo autopath display

==================================================================
HPswsp Version : A.3.0F.02F.02F
==================================================================
Auto Discover : ON
==================================================================
Array Type : EVA-AA
Array WWN : 5000-1FE1-5010-64D0
Read Optimize : ON
Path Verification Period : 00:10
==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-074E-0000
Virtual Device File : /hpap/dsk/hpap11
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d2 Active
/dev/dsk/c21t0d2 Active
/dev/dsk/c23t0d2 Active
/dev/dsk/c25t0d2 Active
/dev/dsk/c27t0d2 Active
/dev/dsk/c29t0d2 Active
/dev/dsk/c31t0d2 Active
/dev/dsk/c33t0d2 Active

==================================================================

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0751-0000
Virtual Device File : /hpap/dsk/hpap12
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d3 Active
/dev/dsk/c21t0d3 Active
/dev/dsk/c23t0d3 Active
/dev/dsk/c25t0d3 Active
/dev/dsk/c27t0d3 Active
/dev/dsk/c29t0d3 Active
/dev/dsk/c31t0d3 Active
/dev/dsk/c33t0d3 Active

==================================================================

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0758-0000
Virtual Device File : /hpap/dsk/hpap13
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d4 Active
/dev/dsk/c21t0d4 Active
/dev/dsk/c23t0d4 Active
/dev/dsk/c25t0d4 Active
/dev/dsk/c27t0d4 Active
/dev/dsk/c29t0d4 Active
/dev/dsk/c31t0d4 Active
/dev/dsk/c33t0d4 Active

==================================================================

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-075B-0000
Virtual Device File : /hpap/dsk/hpap14
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d5 Active
/dev/dsk/c21t0d5 Active
/dev/dsk/c23t0d5 Active
/dev/dsk/c25t0d5 Active
/dev/dsk/c27t0d5 Active
/dev/dsk/c29t0d5 Active
/dev/dsk/c31t0d5 Active
/dev/dsk/c33t0d5 Active

==================================================================

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0775-0000
Virtual Device File : /hpap/dsk/hpap15
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d6 Active
/dev/dsk/c21t0d6 Active
/dev/dsk/c23t0d6 Active
/dev/dsk/c25t0d6 Active
/dev/dsk/c27t0d6 Active
/dev/dsk/c29t0d6 Active
/dev/dsk/c31t0d6 Active
/dev/dsk/c33t0d6 Active

==================================================================

==================================================================
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0737-0000
Virtual Device File : /hpap/dsk/hpap16
Load Balancing Policy : No Load Balancing
Lun Timeout : Infinite Retry (-1)
==================================================================
Device Path Status
==================================================================
/dev/dsk/c19t0d1 Active
/dev/dsk/c21t0d1 Active
/dev/dsk/c23t0d1 Active
/dev/dsk/c25t0d1 Active
/dev/dsk/c27t0d1 Active
/dev/dsk/c29t0d1 Active
/dev/dsk/c31t0d1 Active
/dev/dsk/c33t0d1 Active

==================================================================

==================================================================
James R. Ferguson
Acclaimed Contributor

Re: Help with script

Hi (again):

It looks to me like Hein's variation returns what you want. Copying and pasting Hein's code and running it with your most recent input as posted gave me:

Lun WWN : 6005-08B4-0006-A7DB-0000-E000-074E-0000 /dev/dsk/c19t0d2
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0751-0000 /dev/dsk/c19t0d3
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0758-0000 /dev/dsk/c19t0d4
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-075B-0000 /dev/dsk/c19t0d5
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0775-0000 /dev/dsk/c19t0d6
Lun WWN : 6005-08B4-0006-A7DB-0000-E000-0737-0000 /dev/dsk/c19t0d1

Isn't this what you want?

Regards!

...JRF...
GTownes
Advisor

Re: Help with script

Hi JRF,

Yes, thats exactly what I want it to do. I am copying and pasting the exact syntax, but for some reason its not working for me. I am not sure why its not working for me. Guess I'll keep playing around with it till I can get it to work.

Thanks for your help.


G
James R. Ferguson
Acclaimed Contributor

Re: Help with script

Hi (again):

One way you would _not_ the correct output is if the target strings were preceeded by whitespace. Remember that our solutions anchored ('^') things to the beginning of a line:

/^Lun WWN/

...and...

/^\/dev/

mean that the character sequences only match if they are the first characters on a line.

I would examine your output thusly:

# sudo autopath display | cat -etv

You could be less rigorous by doing:

# awk '/Lun WWN/ {LINE=$0};/\/dev/ ...

...or better (if whitespace preceeding is allowed):

# awk '/[[:space:]]*Lun WWN/ {LINE=$0};/[[:space:]]*\/dev/ && LINE {print LINE, $1;LINE=""}'

Regards!

...JRF...
GTownes
Advisor

Re: Help with script

Ok. Thanks