For a few days now, my internet has been intermittently shutting off in the afternoon and turning back on in the evening (thanks Comcast?). I want to see the exact time at which my connection drops, but unfortunately the ping command does not have built-in timestamp support. Fortunately, the Bash script below adds a thin wrapper around ping in order to add a timestamp in front.
#!/bin/bash
HOST=$@
ping $HOST | while read PONG
do
grep -q ttl <<< "$PONG"
if [ $? -eq 0 ]; then
echo "`date`: $PONG"
else
echo "$PONG"
fi
done
This code comes courtesy of this Unix.StackExchange post, which I have slightly modified. To use it, copy and paste the above code into a file named tping, then chmod +x tping. Its usage is identical to ping. For example,
./tping -c 100 google.com # ping google.com 100 times with timestamp
You can run ./tping with no arguments to see usage.
Additionally, you can download the Bash script here (right-click and save).