Created
April 18, 2016 05:21
-
-
Save duncan-bayne/03422b5121c0cee82e2bd0310d451000 to your computer and use it in GitHub Desktop.
Bounce NetworkManager connections on timeouts
This file contains 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=$1 | |
if [ -z "$SSID" ]; then | |
echo "usage: nmcli-bounce SSID" | |
exit -1 | |
fi | |
HOST=cogent.co | |
SLEEP_AFTER_BOUNCE_S=10 | |
SLEEP_BETWEEN_PINGS_S=1 | |
while true | |
do | |
ping -W 5 -c 1 $HOST > /dev/null | |
if [ $? -ne 0 ]; then | |
# This should imply an up as well, if NM is set to auto-connect. | |
nmcli con down id $SSID | |
if [ $? -ne 0 ]; then | |
(>&2 echo "nmcli-bounce: failed to bounce $SSID") | |
fi | |
sleep $SLEEP_AFTER_BOUNCE_S | |
fi | |
sleep $SLEEP_BETWEEN_PINGS_S | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment