- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Fun awk script. Looking to a possible improvem...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 08:07 AM
07-01-2010 08:07 AM
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
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 08:22 AM
07-01-2010 08:22 AM
Solution# 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 08:28 AM
07-01-2010 08:28 AM
Re: Fun awk script. Looking to a possible improvement
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
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 08:38 AM
07-01-2010 08:38 AM
Re: Fun awk script. Looking to a possible improvement
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
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 08:53 AM
07-01-2010 08:53 AM
Re: Fun awk script. Looking to a possible improvement
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 09:00 AM
07-01-2010 09:00 AM
Re: Fun awk script. Looking to a possible improvement
I almost had it.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 09:18 AM
07-01-2010 09:18 AM
Re: Fun awk script. Looking to a possible improvement
/World/{ print $7;next}â
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 11:23 AM
07-01-2010 11:23 AM
Re: Fun awk script. Looking to a possible improvement
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
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2010 12:04 PM
07-01-2010 12:04 PM
Re: Fun awk script. Looking to a possible improvement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2010 12:31 PM
07-02-2010 12:31 PM
Re: Fun awk script. Looking to a possible improvement
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...