Skip to content

Instantly share code, notes, and snippets.

@trwatson
Last active April 3, 2017 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trwatson/8e8337565e2b136c1c0b5c1bb58bec44 to your computer and use it in GitHub Desktop.
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
#!/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