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).

Published by Geoffrey Liu

A software engineer by trade and a classical musician at heart. Currently a software engineer at Groupon getting into iOS mobile development. Recently graduated from the University of Washington, with a degree in Computer Science and a minor in Music. Web development has been my passion for many years. I am also greatly interested in UI/UX design, teaching, cooking, biking, and collecting posters.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.