Due to certain problems with my ISP my net often gets disconnected. As you can guess there is nothing more frustrating then trying to do something and see that your internet is not working and then manually reconnecting the network. In order to fix this i wrote a simple script to monitor my network at an interval of one minute
#!/bin/bashThe script pings google.com and if less then four pings are successful in five attempts(60%) then a reconnection is performed.
pingout=`ping www.google.com -q -c 5 -W 2`;
total=`echo $pingout| grep transmitted | sed "s/.*\([[:digit:]]\) received.*/\1/"`;
if [[ $total -lt 4 || $pingstatus -ne '0' || $total -eq '' ]]
logger "Internet connection not working.$total/5 pings. Reconnecting..."
notify-send -i modem "Reconnecting" "$total/5 pings failed. Reconnecting..."
logger "Internet connection working properly"
To execute it periodically every minute i just added it to cron by simply executing
in a terminal and adding the following line at the end of the file
* * * * * ~/monitor.sh >/dev/null 2>&1