Skip to content

Instantly share code, notes, and snippets.

@mbenford
Created April 8, 2020 03:10
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 mbenford/d3d042b145c763074e7738ccb88e7940 to your computer and use it in GitHub Desktop.
Save mbenford/d3d042b145c763074e7738ccb88e7940 to your computer and use it in GitHub Desktop.
Starts or stops a VPN connection
#!/bin/bash
set -e
conn_id=$(nmcli conn show | grep vpn | awk '{print $2}' | head -n1)
if [ "$conn_id" == "" ]; then
echo "no VPN connection was found"
exit 1
fi
is_active=$(nmcli conn show --active | grep "$conn_id" | wc -l)
if [ "$is_active" == "0" ]; then
nmcli con up $conn_id
exit 0
fi
echo -n "there is an active VPN connection. disconnect? [y/N] "; read choice
if [[ "$choice" =~ [yY] ]]; then
nmcli con down $conn_id
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment