Skip to content

Instantly share code, notes, and snippets.

@thomasgroch
Forked from yamao2253/reconnect.sh
Last active January 28, 2019 17:32
Show Gist options
  • Save thomasgroch/a6d9336e397732bbc647e90391de2591 to your computer and use it in GitHub Desktop.
Save thomasgroch/a6d9336e397732bbc647e90391de2591 to your computer and use it in GitHub Desktop.
Raspberry Pi WiFi reconnection script
#!/bin/bash
while true
do
# ping -c 1 192.168.0.1
# #test $? -eq 1 && sudo /etc/ifplugd/ifplugd.action wlan0 up
# test $? -ne 0 && sudo /etc/ifplugd/action.d/action_wpa wlan0 up
ping -c2 192.168.0.1 > /dev/null
if [ $? != 0 ]
then
echo "No network connection, restarting wlan0"
/sbin/ifdown 'wlan0'
sleep 5
/sbin/ifup --force 'wlan0'
fi
sleep 7
done
sudo chmod 775 /usr/local/bin/checkwifi.sh
crontab -e
# every 5 minutes
*/5 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment