Skip to content

Instantly share code, notes, and snippets.

@mkoura
Last active February 8, 2018 08:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mkoura/2a6b21e8049f878ebac1 to your computer and use it in GitHub Desktop.
Save mkoura/2a6b21e8049f878ebac1 to your computer and use it in GitHub Desktop.
script for starting/stopping vpn using Network Manager on Linux - can be used via keyboard shortcut
#!/bin/sh
# list of configured VPNs:
# nmcli con show |grep vpn
# PIA London PPTP
uuid="07067b81-d1d8-46cb-8b92-59341c69fe73"
# PIA NL PPTP
#uuid="f8ac9237-4865-4757-a78d-8d525dc846e5"
active_uuid=''
for r in $(nmcli -t -f UUID,TYPE con show --active); do
ctype="${r##*:}"
if [ "$ctype" = 'vpn' ]; then
active_uuid="${r%%:*}"
nmcli con down uuid $active_uuid
break
fi
done
[ -z "$active_uuid" ] && nmcli con up uuid $uuid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment