Skip to content

Instantly share code, notes, and snippets.

@simonwo
Created March 9, 2015 00:45
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 simonwo/dc7a089829b284fb86a5 to your computer and use it in GitHub Desktop.
Save simonwo/dc7a089829b284fb86a5 to your computer and use it in GitHub Desktop.
Script to be called from cron to check Raspberry Pi's wireless connection
#!/bin/bash
# The address of the wireless access point itself
GATEWAY=`netstat -nr | grep wlan0 | grep G | awk '{ print $2 }'`
# Let's try and contact the wireless access point
ping -c 1 $GATEWAY
# Did we succeed? (ping will make $? equal to 1 if it failed, or 0 if it succeeded)
if [[ $? == 1 ]]; then
# Uh oh, couldn't contact the access point.
# Let's bring the wireless down
wpa_cli disconnect
ifconfig wlan0 down
sleep 5
# and then bring it back up
ifconfig wlan0 up
wpa_cli reassociate
fi
# exit 0 to indicate we are happy
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment