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