Skip to content

Instantly share code, notes, and snippets.

@filipsPL
Created April 16, 2020 07:22
Show Gist options
  • Save filipsPL/33433a0938d153e46cb7b3c78d5b5f61 to your computer and use it in GitHub Desktop.
Save filipsPL/33433a0938d153e46cb7b3c78d5b5f61 to your computer and use it in GitHub Desktop.
Bash check if a VPN connection is active, if not - connect!
#!/bin/bash
vpnConnectionName="my vpn connection"
if nmcli c show --active | grep -q "$vpnConnectionName"; then
echo "$vpnConnectionName connection is up"
else
echo "$vpnConnectionName connection is down, let's connect"
nmcli con up id "$vpnConnectionName"
sleep 4s
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment