I’ve been in some situations where I’d like to add timestamp to pings. There could be loads of reasons as to why you’d like to do this, but I used it to check if there where specific times of the day that had higher latency on my internet-connection at home.
If you’re only interested in pings that gets valid replies, the following should work on most systems;
ping google.com | awk '/^[0-9]+ bytes from / { "date" | getline pong; close("date"); print pong":",$0; }'
If you’re interested in all types of replies (unreachable, no route to host, etc), the following should work on most systems;
ping google.com | while read pong; do echo "$(date): $pong"; done
Thanks a lot.. Its indeed working fine..
Can I get a timestamp similar to above by using -M mask | time and how do I use the -M, I can’t get it to work
very useful! nice jobs! thanks!
gr8t, thks
Works great, cheers.
Thanks for this hint, works great!
Thanks a lot!
thanks
Excellent. I used this one with a few ping switches to ping my ISP’s router and DNS to give them evidence that ca 1% of my pings get lost.
Pinging every 10 seconds for 24 hours.
ping -i 10 -c 8640 dns_ip_address | while read pong; do echo “$(date): $pong”; done > Desktop/dns_pings.txt
cool. Thanks I knew there was a way… :-)
thanks
” ping google.com | while read pong; do echo “$(date): $pong”; done ”
This is a line of pure genius. Thanks for sharing!!
roger that! genius
Great! Thanks a mil :)
Genius indeed! Thanks!
Still useful…..and eloquent
Thanks a lot. But it does not show the ping statistics that I get when I do “ping google.com” something like “100 packets transmitted, 75 received, 25% packet loss, time 80015ms” etc. What to do to add ping statistics to above commands?
I’m sorry, this is driving me crazy… PONG? Is that actually a real bash command, AND is it the response to ping? If so I’m lol, that’s cute :) But I can’t find use of it anywhere else… how did you discover this??
PONG is just a variable name. Nothing special at all, not a bash command.
Thanks for posting.
(It took me a second to realize that pong was just a variable too.)
Super helpful, thanks!
I tried this and got this written in blue. I am lost. Any help would be much appreciated.
~ pipe while quotes
terminal didn’t like the quotes… (os x 10.14.5)
After removing them i’ve found my new favorite command :D
ping http://www.apple.com | while read pong; do echo $(date): $pong; done
Love this! So handy and elegant. Piping to a file gives me a record if I need it.
Awesome!
Great, thanks for sharing!