I am trying to extract the ping times in a more data-friendly format. My goal is to turn something like this:
64 bytes from arn06s02-in-f0.1e100.net (173.194.32.32): icmp_seq=59 ttl=54 time=31.8 ms
into something like:
1361999357 31.8
Where the first number comes from $(date +%s) and the second number is the 8th column from the ping command.
I would like to be able to run this for a long time and get a long, two-column list of timestamps and ping times.
Timestamp I have the timestamp working with the following:
ping google.com | while read line; do echo "$(date +%s) $line"; done
But when I try to add sed, awk, or cut into the pipeline to get just the time I end up with no output!
I'm not very familiar with sed or awk, though I'm certain they must be the right tools for the job. My attempts have resulted in no output.. I think it is because awk is expecting an EOF before passing the output to the next piped program?
Thanks!
Using awk :
$ ping google.com | awk -F'[ =]' 'NR>1{print system("echo -n $(date +%s)"), $11}'
Short & efficient, no ? =) And no buffering problems occurs...
Note : system("") can be used as a hack to avoid buffering.
Try this:
ping -c 1 google.com | grep "bytes from" | while read line; do echo "$(date +%s) $line"; done | awk '{print $1 " " $8}' | sed 's,time=,,'
Note that if you leave off the '-c', there's a certain amount of buffering that happens before you get any output. Leaving the '-c' lets you see the results more quickly and to verify that things are working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With