Skip to content

Instantly share code, notes, and snippets.

@baongoc124
Last active September 10, 2015 09:35
Show Gist options
  • Select an option

  • Save baongoc124/c94e7b0c123bf25d26be to your computer and use it in GitHub Desktop.

Select an option

Save baongoc124/c94e7b0c123bf25d26be to your computer and use it in GitHub Desktop.
Keep wifi network connected by pinging gateway regularly and reconnect if needed
#!/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