Last active
September 10, 2015 09:35
-
-
Save baongoc124/c94e7b0c123bf25d26be to your computer and use it in GitHub Desktop.
Keep wifi network connected by pinging gateway regularly and reconnect if needed
This file contains hidden or 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
| #!/bin/bash | |
| SSID=mywifi | |
| uuid=$(nmcli c | grep $SSID | tr -s ' ' | cut -d\ -f3) | |
| while :; do | |
| sleep 1s | |
| ping $(ip r | grep -oP "(?<=default via )[0-9.]*") -c2 -w8 > /dev/null | |
| if [[ $? -ne 0 ]]; then | |
| notify-send "Disconnected" | |
| echo "==> " $(date) " Reconnecting" | |
| nmcli c up uuid ${uuid} | |
| else | |
| echo "==> OK, connected!" | |
| sleep 15s | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment