Run Continuous Ping in the Background Including Timestamp and Logging

When trying to troubleshoot network or Internet related connectivity issues, it may be helpful to have a system on the inside network pinging a reliable destination on the Internet to test connectivity and log the output with a timestamp to find the specific times when an outage occurred.

Here is the command within Linux I used for this:

nohup ping 1.1.1.1 | while read result; do echo "$(date): $result"; done > /home/user/pinglog.txt &

Including “nohup” makes it so this command continues to run even when the session to the system is closed. When you run this command without “nohup” and you close the SSH session to that Linux host, the command will stop executing. The “&” at the end makes this command run in the background on the system.

The command takes the ping output and creates a variable called “result”. The time is added and then the “result” variable is output.