Skip to content

Instantly share code, notes, and snippets.

@JoshMcCullough
Last active June 21, 2018 14:38
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 JoshMcCullough/9d3cfbcc423d74ae9ecde648dc6813c1 to your computer and use it in GitHub Desktop.
Save JoshMcCullough/9d3cfbcc423d74ae9ecde648dc6813c1 to your computer and use it in GitHub Desktop.
Connect to an openvpn server based on a pattern.
#!/bin/sh
if [ ! $(id -u) = 0 ]; then
echo "This script must be run as root."
exit 1
fi
pattern=$1;
match="$(find ~/.openvpn/ -name 'client.ovpn' |grep $pattern |head -n 1)"
if [ -z match ]; then
echo "No 'client.conf' or directoy found matching pattern '$pattern' within path: $path"
else
echo "Connecting to VPN using: $match"
exec openvpn $match
fi
@JoshMcCullough
Copy link
Author

This assumes you have VPN configs within ~/.openssh/[connection name]/client.ovpn.

#Usage

sudo ./vpn.sh pattern

Where pattern is a regex used to location the VPN connection's folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment