Skip to content

Instantly share code, notes, and snippets.

@digitalist
Forked from dizcza/checkwifi.sh
Created July 27, 2021 06:06
Show Gist options
  • Save digitalist/9a0556b96a288a7f7bb7d558704c8b4f to your computer and use it in GitHub Desktop.
Save digitalist/9a0556b96a288a7f7bb7d558704c8b4f 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