Created
August 14, 2014 09:20
-
-
Save lanceliao/06f12a7f9e4cd8178d80 to your computer and use it in GitHub Desktop.
Raspberry Pi WIFI protect script - auto reconnect when AP is powered on after a powered off. call this script in crontab.
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 | |
export PATH=$PATH:/sbin | |
# Auto reconnect to specified WIFI access point if there is no internect connection | |
# Author: Lance | |
# Website: http://www.shuyz.com | |
# Last updated: 2013/05/25 | |
#your WIFI SSID here to be auto connect | |
SSID=ShuYZ | |
date | |
if ifconfig eth0 | grep -q "inet addr:" ; then | |
echo "Wired connection OK, skip checking wifi." | |
else | |
echo "No wired connection, checking WIFI..." | |
if ifconfig | grep -q "wlan0" ; then | |
if ifconfig wlan0 | grep -q "inet addr:" ; then | |
echo "Wireless connection OK." | |
else | |
if iwlist wlan0 scan | grep -q ${SSID} ; then | |
echo "WIFI access point ${SSID} found, reconnectting..." | |
sudo ifup --force wlan0 | |
# sudo reboot | |
else | |
echo "WIFI access point ${SSID} not found!" | |
fi | |
fi | |
else | |
echo "Wireless adapter not found!" | |
fi | |
fi | |
echo "job done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment