Skip to content

Instantly share code, notes, and snippets.

@dizcza
Created June 9, 2018 08:57
Show Gist options
  • Save dizcza/806c8b831ed5e978901dea835f5334e8 to your computer and use it in GitHub Desktop.
Save dizcza/806c8b831ed5e978901dea835f5334e8 to your computer and use it in GitHub Desktop.
Ubuntu restart WiFi service automatically
#!/bin/bash
# sudo crontab -e
# @reboot /home/dizcza/Programs/checkwifi.sh
# sudo update-rc.d cron defaults
/bin/sleep 30
while true; do
/usr/bin/wget -T5 -q --spider google.com
code=$?
/bin/echo "$(date +'%D %H:%M:%S') code ${code}" >> /home/dizcza/checkwifi.log
if [ ${code} -ne 0 ]; then
/usr/bin/nmcli radio wifi off
/bin/sleep 5
/usr/bin/nmcli radio wifi on
/bin/sleep 10
/usr/sbin/service network-manager restart
/bin/echo "RESTARTED ${code}" >> /home/dizcza/checkwifi.log
fi
/bin/sleep 20
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment