Created
March 9, 2015 00:45
-
-
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
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 | |
# 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