Skip to content

Instantly share code, notes, and snippets.

@jonasbjork
Created August 25, 2015 16:03
Show Gist options
  • Select an option

  • Save jonasbjork/92b41ceb7c52c1a50b64 to your computer and use it in GitHub Desktop.

Select an option

Save jonasbjork/92b41ceb7c52c1a50b64 to your computer and use it in GitHub Desktop.
Check wifi connection on RPi2 and reboot if no connection.
#!/usr/bin/env bash
# Script for checking wifi connection on my headless, hidden, Raspberry Pi 2
# The idea is to reboot the RPi2 when network connection is lost, so it can come
# up again. Making administration efforts minimal.
# Crontab:
# 0,10,20,30,40,50 * * * * /home/pi/checkwifi.sh
logger -t checkwifi "Checking wifi"
# Change 192.168.0.1 to your router IP-address, or use Google DNS 8.8.8.8
ping -c4 192.168.76.1 > /dev/null
if [ $? != 0 ]
then
logger -t checkwifi "Wifi not OK, rebooting"
sudo /sbin/shutdown -r now
fi
logger -t checkwifi "Wifi OK, no reboot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment