Last active
December 21, 2021 17:16
-
-
Save draptik/9f4b472da9f315aeeb3b to your computer and use it in GitHub Desktop.
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
crontab -e | |
*/5 * * * * /usr/bin/sudo -H /home/pi/my-scripts/checkwifi.sh >> /dev/null 2>&1 |
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
# http://weworkweplay.com/play/rebooting-the-raspberry-pi-when-it-loses-wireless-connection-wifi/ | |
# Check wifi connection... | |
ping -c4 192.168.179.3 > /dev/null | |
# '$?' is the exit code of previous ping command. | |
# If exit code != 0 (failure)... | |
if [ $? != 0 ] | |
then | |
echo "$(date): No network connection, restarting wlan0" >> /var/log/checkwifi.log | |
# deactivate wifi... | |
/sbin/ifdown 'wlan0' | |
sleep 5 | |
# Restart wifi... | |
/sbin/ifup --force 'wlan0' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
# deactivate wifi...
ip link set wlan0 down
sleep 5
# Restart wifi...
ip link set wlan0 up