Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I timestamp every ping result?

Ping returns this by default:

64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms 

Is there some way I can get it to add the timestamp?

For example,

Mon 21 May 2012 15:15:37 EST | 64 bytes from 203.173.50.132: icmp_seq=0 ttl=244 time=57.746 ms 

I'm on OS X v10.7 (Lion) which seems to have some BSD version of ping.

like image 663
John Mee Avatar asked May 21 '12 05:05

John Mee


People also ask

How do you ping a timestamp on a Mac?

Fortunately, ping on macOS lets you easily add a timestamp with a single additional option. Just enter ping --apple-time <IP address> to see the time a packet was received, right down to the microsecond.


1 Answers

I could not redirect the Perl based solution to a file for some reason so I kept searching and found a bash only way to do this:

ping www.google.fr | while read pong; do echo "$(date): $pong"; done

Wed Jun 26 13:09:23 CEST 2013: PING www.google.fr (173.194.40.56) 56(84) bytes of data. Wed Jun 26 13:09:23 CEST 2013: 64 bytes from zrh04s05-in-f24.1e100.net (173.194.40.56): icmp_req=1 ttl=57 time=7.26 ms Wed Jun 26 13:09:24 CEST 2013: 64 bytes from zrh04s05-in-f24.1e100.net (173.194.40.56): icmp_req=2 ttl=57 time=8.14 ms 

The credit goes to https://askubuntu.com/a/137246

like image 135
richk Avatar answered Oct 14 '22 06:10

richk