Log of lost internet connections

I am having a big problem with lost internet connections with my DSL.

I would like to create a log to be able to show the technician when he comes next week.

I would like for it to only log pings that generate 100% packet loss. Thanks..

This script generates all ping attempts including successful ones.

while true; do

date >> Internet_Connection_Log.txt
echo >> Internet_Connection_Log.txt
ping  47.182.239.232 -c 1 >> Internet_Connection_Log.txt
echo >> Internet_Connection_Log.txt
sleep 180
done

Make the logging dependent on the RC of ping:

while : ; do
     if ! ping  -c 1 47.182.239.232 ; then
          printf "\n%s\n" "ping failed at $(date)" >> Internet_Connection_Log.txt
     fi
     sleep 180
done

But wouldn't a log with start- and end-times of failures be better? Note that this makes sense only if the blocks of good and failing internet connections are longer - if it works 10 minutes, then fails for 10 minutes this would make sense, if every second ping fails but every other packet gets through this would create a very large log:

lFail=0
while : ; do
     if (( lFail )) ; then
          if ping  -c 1 47.182.239.232 ; then
               printf "\n%s\n" "ping worked again at $(date)" >> Internet_Connection_Log.txt
               lFail=0
          fi
     else
          if ! ping  -c 1 47.182.239.232 ; then
               printf "\n%s\n" "ping stopped working at $(date)" >> Internet_Connection_Log.txt
               lFail=1
          fi
     fi
     sleep 1
done

I hope this helps.

bakunin

Thanks.

I will try the first one you listed.

My lost connections only last about 30 seconds until the modem re-connects.

--- Post updated at 04:58 PM ---

It worked great.

ping failed at Sat Jan 12 16:56:28 CST 2019

I noticed I am getting dropped connections about every 20 minutes.

So you want a log of the ups and downs of your DSL connection? Depending on your ping version ( ping -V , mine is "ping utility, iputils-s20180629"), a single command might suffice:

ping -Di5 router
PING router.domain.De (192.168.0.1) 56(84) bytes of data.
[1547335266.088652] 64 bytes from router.domain.De (192.168.0.1): icmp_seq=1 ttl=64 time=1.67 ms
[1547335271.094225] 64 bytes from router.domain.De (192.168.0.1): icmp_seq=2 ttl=64 time=1.44 ms
[1547335276.099867] 64 bytes from router.domain.De (192.168.0.1): icmp_seq=3 ttl=64 time=1.48 ms

Adapt the interval ( -i ) value to the desired granularity.

I just need the times when router is down.

Added this for an audio reminder.

cvlc --play-and-exit /usr/share/sounds/My_Sounds/Alarm-sound-buzzer.mp3