Skip to content

Instantly share code, notes, and snippets.

@yorch
Last active October 16, 2016 17:30
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 yorch/aeb4aa1f0f190eadce414e5ade4a9fec to your computer and use it in GitHub Desktop.
Save yorch/aeb4aa1f0f190eadce414e5ade4a9fec to your computer and use it in GitHub Desktop.
Rasbperry Pi WLAN Network Monitor
#!/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