Created
April 10, 2015 19:38
-
-
Save baydam/cb61a248598dc1c216de to your computer and use it in GitHub Desktop.
This Script reboot the modem router after verifying if internet connection gone down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Dame Diongue | |
# This script checks for an active Internet connection by trying to access | |
# If check fail, it will reboot the Modem Router | |
# Trying to access | |
wget -t 1 -T 10 -o wgetout "http://www.google.sn" | |
# Wait 5 secondes | |
sleep 5 | |
httpRequest=`cat wgetout | gawk '/Resolving/{ print $4 }' | tr -d ':'` | |
if [ "$httpRequest" == "failed" ] | |
then | |
# Restart the modem through cable or wireless connection | |
(sleep 3;echo admin;sleep 3;echo admin;sleep 3;echo reboot;sleep 3;) | telnet 192.168.1.1 | |
# Leave tracks on log file | |
# Need to set 777 chmod permission if write in /var/log/ | |
echo 'Restarting modem router - '`date +%c` >> /var/log/internet_check.log | |
fi | |
# Cleaning garbage | |
rm index.html* wgetout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment