Skip to content

Instantly share code, notes, and snippets.

@duncan-bayne
Created April 18, 2016 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncan-bayne/03422b5121c0cee82e2bd0310d451000 to your computer and use it in GitHub Desktop.
Save duncan-bayne/03422b5121c0cee82e2bd0310d451000 to your computer and use it in GitHub Desktop.
Bounce NetworkManager connections on timeouts
#!/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