Last active
April 3, 2017 01:43
-
-
Save trwatson/8e8337565e2b136c1c0b5c1bb58bec44 to your computer and use it in GitHub Desktop.
checks if it can connect to the internet - restarts router if fails - XyXEL CenturyLink Router Restart
This file contains 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 | |
check_connection(){ | |
checkMyIP='' | |
checkGoogle='' | |
checkMyIP=$(curl -s icanhazip.com | egrep [0-9] | head -n1 | wc -l) | |
checkGoogle=$(curl -s google.com | grep HEAD | head -n1 | wc -l) | |
internetHealth=$(echo $checkMyIP+$checkGoogle|bc) | |
printf "$internetHealth" | |
} | |
timestamp() { | |
date +"%T" | |
} | |
connectionCount=$(check_connection) | |
if [[ "$connectionCount" -lt "2" ]] | |
then | |
tryAgain=$(check_connection) | |
if [[ "$tryAgain" -lt "2" ]] | |
then | |
printf "$(timestamp) - failed, restarting\n" >> connection.log | |
/home/pi/restart_router | |
##### contents of expect script | |
##!/usr/bin/expect | |
#set timeout 1 | |
#spawn telnet 192.168.0.1 | |
#expect "Login:" { | |
# send "admin\r" | |
# expect "password:" | |
# send "PASSWORD\r" | |
# expect ">" | |
# send "reboot\r" | |
#} | |
#expect eof | |
fi | |
else | |
printf "`timestamp` - all good\n" >> connection.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment