Last active
October 16, 2016 17:30
-
-
Save yorch/aeb4aa1f0f190eadce414e5ade4a9fec to your computer and use it in GitHub Desktop.
Rasbperry Pi WLAN Network Monitor
This file contains hidden or 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 | |
HOST=www.google.com | |
while true ; do | |
if ifconfig wlan0 | grep -q "inet addr:" ; then | |
#$printf "WLAN connected, IP: %s\n" $(hostname -I) | |
sleep 60 | |
else | |
echo "Network connection down! Attempting reconnection." | |
# First try | |
ifconfig wlan0 down | |
sleep 3 | |
ifconfig wlan0 up | |
sleep 10 | |
iwconfig wlan0 essid any | |
sleep 10 | |
ping -c 1 -W 10 $HOST &>/dev/null | |
if [ $? -eq 0 ]; then | |
exit | |
else | |
# Second try | |
service networking restart | |
iwconfig wlan0 essid any | |
sleep 10 | |
ping -c 1 -W 10 $HOST &>/dev/null | |
fi | |
sleep 30 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment