Skip to content

Instantly share code, notes, and snippets.

@imsurinder90
Last active July 24, 2018 10:40
Show Gist options
  • Save imsurinder90/c676f08ae1053aaf5430ea4f13d09d9a to your computer and use it in GitHub Desktop.
Save imsurinder90/c676f08ae1053aaf5430ea4f13d09d9a to your computer and use it in GitHub Desktop.
Restart WiFi in Raspberry PI when connection drops
create a new file /usr/local/bin/restart_wifi.sh
and put below script in it.
ping -c4 192.168.1.1 > /dev/null
if [ $? != 0 ]
then
echo "No network connection, restarting wlan0"
sudo systemctl daemon-reload
sleep 5
sudo systemctl restart dhcpcd
fi
then
Now make it executable:
sudo chmod 775 /usr/local/bin/restart_wifi.sh
Then add it to a crontab
*/5 * * * * /usr/bin/sudo -H /usr/local/bin/restart_wifi.sh >> /dev/null 2>&1
This command will check every 5 minute if wifi is stopped or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment