LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Using ping to detect network failures (https://www.linuxquestions.org/questions/linux-networking-3/using-ping-to-detect-network-failures-506815/)

Electric-Gerbil 12-02-2006 08:28 AM

Timestamping each line of 'ping' output
 
Currently, my home internet connection is very unstable - it drops out every few minutes. Understandably very annoying. So I'm trying to use the ping command to find out when the internet connection fails. This method works fine for when I just want to detect that a failure's occurred, but I also want to be able to determine the time at which these failures occurred.

As such, I'm wondering if there's any way I can get the console to show a timestamp for each line of output from the ping command, and ideally if this output can also be written to a file at the same time it appears on the console.

Many thanks in advance for any assistance rendered.

- EG

fordeck 12-02-2006 09:57 AM

You could run a small script via cron, for example:

Code:

#!/bin/bash

ping -c 2 $1 1>/dev/null

if [ "$?" = 1 ]
then
    echo "`date` : Network down" >> /path-to/ping-log
fi



All times are GMT -5. The time now is 10:39 AM.