If you are connected to a VPN, this command will return a list of established 
VPN connections:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$'

This command will list the IDs of any established vpn connections (one per 
line):
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP 
'^.*?(?=\s{2,})'

So to disconnect all VPN connections you could do it based on this ID like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP 
'^.*?(?=\s{2,})' | sed 's/^/\x27/' | sed 's/$/\x27/' | xargs -L1 nmcli con down 
id

However, perhaps it is better to do this using the UUIDs.

You can list the UUIDs of all established VPN connections like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP 
'(?<=[\s]{2})[^\s]+(?=(\s+[^\s]+){2}\s+yes.*)'

So you can disconnect all established VPN connections by UUID like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP 
'(?<=[\s]{2})[^\s]+(?=(\s+[^\s]+){2}\s+yes.*)' | xargs -L1 nmcli con down uuid

Perhaps this logic could be added to nmcli, so that this following proposed 
option would concisely achieve the same results:
nmcli con down allvpn

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1338382

Title:
  nmcli - Disconnect VPN Without Specifying ID or UUID

To manage notifications about this bug go to:
https://bugs.launchpad.net/network-manager/+bug/1338382/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to