- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting ? for you geniuses
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
Forums
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
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
10-29-2004 04:49 AM
10-29-2004 04:49 AM
Scripting ? for you geniuses
EX:
ping -c 20 x.x.x.x
Results come back with the following:
20 packets transmitted, 20 received, 0% packet loss, time 9685ms
rtt min/avg/max/mdev = 9.499/17.464/73.811/14.868 ms, pipe 2
I want to set a variable to the % packet loss and another to the max round trip time.
So in this example:
PACKELOSS=0
MAXRTT=73.811
Thoughts on the most efficient way to do this?
TIA and points for all responses.
Sean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 04:58 AM
10-29-2004 04:58 AM
Re: Scripting ? for you geniuses
PACKELOSS=`ping x.x.x.x -n 20 | grep transmitted | awk '{print $ 7}'`
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 05:02 AM
10-29-2004 05:02 AM
Re: Scripting ? for you geniuses
PACKETLOSS=$(cat /tmp/file.dat | awk 'print $6')
tmpmax=$(cat /tmp/file.dat | awk 'print $13')
#You may have to change $6 to $7, just experiment until you get the right data.
You should be able to process $tmpmax through awk to seperate out the slashes and 'print $3' to get the value you want. I don't have exact code for that.
MAXRTT=$(awk -f/ .... '{print $3}'
Hope this is a start.
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
10-29-2004 05:05 AM
10-29-2004 05:05 AM
Re: Scripting ? for you geniuses
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 05:07 AM
10-29-2004 05:07 AM
Re: Scripting ? for you geniuses
ping -c 20 x.x.x.x > /tmp/ping.out
PACKET_LOSS=$(grep "^20 packets" /tmp/ping.out | awk -F, '{print $3}' | awk '{print $1}' | sed 's/\%//'))
MAXRTT=$(grep "^rtt" /tmp/ping.out | awk -F"/" '{print $6}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 05:13 AM
10-29-2004 05:13 AM
Re: Scripting ? for you geniuses
Try,
ping -c 20 x.x.x.x > /tmp/file.dat
PACKELOSS=`cat /tmp/file.dat |grep "packets transmitted"|cut -f 3 -d ","|cut -f 1 -d "%"`;echo "PACKELOSS=$PACKELOSS"
MAXRTT=`cat /tmp/file.dat |grep "min/avg/max" |cut -f 6 -d "/"`;echo "MAXRTT=$MAXRTT"
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 05:21 AM
10-29-2004 05:21 AM
Re: Scripting ? for you geniuses
e.g. ping_out=`ping -c 20 x.x.x.x`
PACKETLOSS=`echo $ping_out |awk .... `
Then wouldn't have to run ping twice or write it to a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 05:52 AM
10-29-2004 05:52 AM
Re: Scripting ? for you geniuses
RESULTS=$( ping -c 20 x.x.x.x )
PACKETLOSS=$( echo $RESULTS | awk '{ print $7 } | cut -f 1 -d \% )
MAXRTT=$( echo $RESULTS | cut -f 6 -d \/ )
This doesn't seem to be an HP /usr/sbin/ping, btw. I needed to use
RESULTS=$( /usr/sbin/ping nj048sps.unix.us.ups.com -n 10 | tail -2 )
to get similar output to what you have above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2004 06:02 AM
10-29-2004 06:02 AM
Re: Scripting ? for you geniuses
What is the REAL problem you are trying to solve?
What are you goign to do with those variables?
You may find is more attractive/easy/efficient to just do all you have to do in awk or perl, without the need of temp file or temp variables.
Cheers,
Hein.