How to log Internet connection drops

ipmonitoringping

I need to execute a script as soon as my raspberry pi gets connected to the Internet. However I was wondering if there was a better way than just pinging Google every minute or so.

My problem is that my Internet connection drops 1-2 times during the day so I need a way to log such events.
It's just the ADSL dropping during the day, I was looking for some way to log when it occurs even when i don't notice it. I think I'll setup a script as suggested.

Best Answer

you can make a check on:

cat /sys/class/net/wlan0/carrier

where wlan0 is my internet interface. you can use whatever interface you are using , such as eth0 , eth1 , wlan0 for internet connectivity. if the output of that command is 1 then you are connected. otherwise not.so you may write script like this:

#!/bin/bash
# Test for network conection
for interface in $(ls /sys/class/net/ | grep -v lo);
do
if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then ; echo "online"; fi
done

you can also use the command:

#hwdetect --show-net

this script also works well:

#!/bin/bash

WGET="/usr/bin/wget"

$WGET -q --tries=20 --timeout=10 http://www.google.com -O   /tmp/google.idx &> /dev/null
if [ ! -s /tmp/google.idx ]
then
  echo "Not Connected..!"
else
  echo "Connected..!"
fi