- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Extracting ping information
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
08-21-2002 10:34 PM
08-21-2002 10:34 PM
I would like to extract the output of the ping command in a comma deliminated format.
For e.g.,
$ ping microsoft.com -n 2
This will display the last 2 lines as:
8 packets transmitted, 8 packets received, 0% packet loss
round-trip (ms) min/avg/max = 4/6/13
I would like to get the output in the output file as:
-----------------------------------------------
MICROSOFT.COM DATE/TIME MIN,AVG,MAX 4,6,13
----------------------------------------------
I can use the following command to get the last 2 lines:
$ ping microsoft.com -n 2 | grep -e
Hope this's not a difficult steps.
Thankx
Sanjay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 10:50 PM
08-21-2002 10:50 PM
Re: Extracting ping information
try this:
host=microsoft.com
ping $host -n 2 |awk -vhost=$host '/^round-trip/{
gsub("/",",",$NF)
print host " '"$(date '+%m/%d/%Y %H:%M')"' " "MIN,AVG,MAX " $NF
}'
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 10:56 PM
08-21-2002 10:56 PM
Re: Extracting ping information
Try something like the following - I'm well aware there are shorter ways to reach the same results but the commands have been written for clarity!!!
SYS=hpx87
STAT=`ping $SYS -n 2 | tail -1`
NUMS=`echo $STAT | awk '{print $5}'`
MIN=`echo $NUMS | cut -d'/' -f1`
AVG=`echo $NUMS | cut -d'/' -f2`
MAX=`echo $NUMS | cut -d'/' -f3`
echo "$SYS : `date` : $MIN,$AVG,$MAX"
Ollie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 11:36 PM
08-21-2002 11:36 PM
Re: Extracting ping information
I really appreciate for your quick help. I need to further add the packet loss values after the MIN/AVG/MAX values, so that it can read as MIN/AVG/MAX/PCKTLOSS w,x,y,z.
Plus if it's not able to ping the server at any point of time, it should redirect the error mesg. to another output file.
Thanks once again.
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 12:34 AM
08-22-2002 12:34 AM
SolutionTry something like:
========================================
#!/usr/bin/ksh
file=/tmp/ping.$$
host=$1
ping $host 8 -n 1 > $file 2>&1
grep -q -e unknown -e 100% $file
if [ $? -eq 0 ] ; then
cat $file >> /tmp/ping.err
rm $file
exit 1
fi
rm $file
date=`date "+%d/%m/%y-%H:%M"`
ping $host -n 2 |
awk '/packet loss/{pl=$(NF-2)}
/round-trip/{n=split($NF,v,"/")}
END{printf("%s %s %s,%s,%s,%s\n",host,date,v[1],v[2],v[3],pl)}' host=$host date="$date"
=============================================
Errors stored in /tmp/ping.err
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 12:59 AM
08-22-2002 12:59 AM
Re: Extracting ping information
Thanks for the details. I really appreciate. I've run the script and is working perfectly fine but when the host is not reachable it gives the following error mesg:
cat: Cannot use /...../ping:xxxx as both input and output.
Hope you can light something on this.
Regards,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 01:18 AM
08-22-2002 01:18 AM
Re: Extracting ping information
Can you show me the output of the 1st ping command for this host please?
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 03:17 PM
08-22-2002 03:17 PM
Re: Extracting ping information
The output of the command is:
myserver.com 23/08/02-09:39 11,14,18,0%
But when the host is unreachable (wrong host name) it gives the following output:
cat: Cannot use /home/skverma/SCRIPTS/tmp/ping.test as both input and output.
Hope this is what you requried?
~Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 03:28 PM
08-22-2002 03:28 PM
Re: Extracting ping information
Thanks for your contribution. Yes, I've checked and it's working fine but I would like to enhance it to include the packet loss also and if the server is not reachable, the error to be re-directed in some other output file.
Hope this's not very difficult.
~Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 03:55 PM
08-22-2002 03:55 PM
Re: Extracting ping information
I've modified the script like this:
$ cat 3_script
HOST=myserver.com
STAT=`ping $HOST -n 2 | tail -1`
NUMS=`echo $STAT | awk '{print $5}'`
MIN=`echo $NUMS | cut -d'/' -f1`
AVG=`echo $NUMS | cut -d'/' -f2`
MAX=`echo $NUMS | cut -d'/' -f3`
NO_PING=`ping melsrv1 -n 1 | tail -2 | grep -i loss`
A_OUTPUT=`echo $NO_PING | awk '{print $7}'`
LOSS=`echo $A_OUTPUT | cut -d '%' -f1`
echo "$HOST: `date` : "MIN,AVG,MAX,LOSS: " $MIN,$AVG,$MAX,$LOSS"
It's been a long time since I've brushed my scripting skill. But now only I need to capture the output in other file if the host is not available.
Thanks
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2002 08:19 PM
08-25-2002 08:19 PM
Re: Extracting ping information
SKV