Operating System - HP-UX
1752576 Members
4453 Online
108788 Solutions
New Discussion

Re: Fun awk script. Looking to a possible improvement

 
SOLVED
Go to solution
Steven E. Protter
Exalted Contributor

Fun awk script. Looking to a possible improvement

I had a need to display some hardware information to update some documentation.

So I created this: http://www.hpux.ws/?p=149

ioscan -fnkCfc | awk ‘/fcd/ {getline;fcd=$NF;print fcd,$2 }’ | while read -r fdev
do
fcmsutil $fdev | awk ‘/Hardware / {print $5}’
fcmsutil $fdev | awk ‘/World / { print $7}’
done

I'm pushing myself to be more awkful and am wondering how I would go about combining the two fcmsutil statements and running fcmsutil only once to save on cpu usage. Not that I should care on a superdome, but I need to do this for work and I find this extremely fun to do.

What I'm thinking is a little awk for loop to roll through and getline and then select the ouput I want.

My awk guru is out of the office today, so I will first do the job and actually update the dcoumentation and then continue to hack around with the awk.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
12 REPLIES 12
James R. Ferguson
Acclaimed Contributor
Solution

Re: Fun awk script. Looking to a possible improvement

Hi Sep:

# cat ./ascript
#!/usr/bin/sh
ioscan -kfnC fc | awk '/fcd/ {getline;fcd=$NF;print fcd,$2}' | while read -r fdev
do
fcmsutil ${fdev} | awk '/Hardware / {print $5};/World / { print $7}'
done

...that is, simply specify your multiple pattern matches and their statements as shown.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Fun awk script. Looking to a possible improvement

Didn't realize it was that simple.

Happy to put you 10 points closer to me JRF, you are truly the more gifted admin.

To earn another 10, I was thinking I wanted to format the data

PATH WWN node WWN port WWN port WWN node

I am updating the blog after I test and making an attempt to format the output.

The formatting makes it easier to create live documanation.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: Fun awk script. Looking to a possible improvement

Working on something here.

ioscan -kfnC fc | awk '/fcd/ {getline;fcd=$NF;print fcd,$2}' | while read -r fde
v
do
fcmsutil ${fdev} | awk '/Hardware / {print $5};/World / { print $7}' | awk '
{printf "%s %s %s %s %s\n",$1, $2, $3, $4, $5}'

The line break is not working out here.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Fun awk script. Looking to a possible improvement

Hi (again) SEP:

Perhaps formatted like this:

# ./ascript
#!/usr/bin/sh
ioscan -kfnC fc | awk '/fcd/ {getline;fcd=$NF;print fcd,$2}' | while read -r fdev
do
fcmsutil ${fdev} | \
awk '/Hardware Path/ {PATH=$5};
/N_Port Node/ {NNODE=$7};
/N_Port Port/ {NPORT=$7};
/Switch Port/ {SPORT=$7};
/Switch Node/ {SNODE=$7};
END{print PATH, NNODE, NPORT, SPORT, SNODE}
'
done

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: Fun awk script. Looking to a possible improvement

Thanks JRF.

I almost had it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Victor Fridyev
Honored Contributor

Re: Fun awk script. Looking to a possible improvement

fcmsutil $fdev | awk â /Hardware / {print $5;next}
/World/{ print $7;next}â

HTH
Entities are not to be multiplied beyond necessity - RTFM
Steven E. Protter
Exalted Contributor

Re: Fun awk script. Looking to a possible improvement

Shalom,

ITRC or your browser or notepad tool ate your output Victor.

fcmsutil $fdev | awk '/Hardware / {print $5;next}
/World /{ print $7;next}'

That is how I interpret your entry.

I'm posting 8 points to the response because you were a great boss.

This issue is resolved, but I'm totally willing to see and reward other approaches.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Victor Fridyev
Honored Contributor

Re: Fun awk script. Looking to a possible improvement

You interpret it correctly. Please, without points.
Entities are not to be multiplied beyond necessity - RTFM
James R. Ferguson
Acclaimed Contributor

Re: Fun awk script. Looking to a possible improvement

Hi (again) SEP:

As Victor showed, we should really stop matching as soon as a pattern is found. Adding 'next' to the action statement for each pattern is one way. Another is to write a cascading 'if/else':

# cat ./ascript
#!/usr/bin/sh
ioscan -kfnC fc | awk '/fcd/ {getline;fcd=$NF;print fcd,$2}' | while read -r fdev
do
fcmsutil ${fdev} | \
awk '
{if (/Hardware Path/) {
PATH=$5
} else if (/N_Port Node/) {
NNODE=$7
} else if (/N_Port Port/) {
NPORT=$7
} else if (/Switch Port/) {
SPORT=$7
} else if (/Switch Node/) {
SNODE=$7
}
}
END{print PATH, NNODE, NPORT, SPORT, SNODE}
'
done


Regards!

...JRF...