Skip to content

Instantly share code, notes, and snippets.

@andycasey
Created July 7, 2017 00:24
Show Gist options
  • Select an option

  • Save andycasey/af49593b3fb77d5adbfbfac50a876cb8 to your computer and use it in GitHub Desktop.

Select an option

Save andycasey/af49593b3fb77d5adbfbfac50a876cb8 to your computer and use it in GitHub Desktop.
# Script to monitor and restart wireless access point when needed
maxPloss=10 #Maximum percent packet loss before a restart
restart_networking() {
# Add any commands need to get network back up and running
/etc/init.d/networking restart
#only needed if your running a wireless ap
/etc/init.d/dhcp3-server restart
}
# First make sure we can resolve google, otherwise 'ping -w' would hang
if ! $(host -W5 www.google.com > /dev/null 2>&1); then
#Make a note in syslog
echo "wap_check: Network connection is down, restarting network ..."
restart_networking
exit
fi
# Initialize to a value that would force a restart
# (just in case ping gives an error and ploss doesn't get set)
ploss=101
# now ping google for 10 seconds and count packet loss
ploss=$(ping -q -w10 www.google.com | grep -o "[0-9]*%" | tr -d %) > /dev/null 2>&1
if [ "$ploss" -gt "$maxPloss" ]; then
echo "Packet loss ($ploss%) exceeded $maxPloss, restarting network ..."
restart_networking
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment