Skip to content

Instantly share code, notes, and snippets.

@cpoliver
Forked from mkoura/vpn-toggle
Last active February 8, 2018 08:22
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 cpoliver/44f73549ac72e12748c56ce8e89e615e to your computer and use it in GitHub Desktop.
Save cpoliver/44f73549ac72e12748c56ce8e89e615e 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`
uuid="049b2d60-b816-4640-b33e-659920598c19"
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