Skip to content

Instantly share code, notes, and snippets.

@mjnaderi
Last active March 25, 2023 14:21
Show Gist options
  • Save mjnaderi/d4b50c76e0bb5fc0d066 to your computer and use it in GitHub Desktop.
Save mjnaderi/d4b50c76e0bb5fc0d066 to your computer and use it in GitHub Desktop.
UpVPN (reconnect vpn when disconnected)
#!/bin/bash
# Usage:
# ./upvpn.sh "VPN Connection Name"
VPN="$1"
trap "exit 0" SIGINT SIGTERM
while true; do
if ! nmcli con show --active | grep -q "$VPN"; then
echo "[`date`] Disconnected. Trying to reconnect..."
nmcli -p con up id "$VPN"
sleep 5
fi
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment