Created
February 1, 2017 13:03
-
-
Save sanderv32/06cc13813412bf8c64df49e206cd3279 to your computer and use it in GitHub Desktop.
Example of how to use CloudMonkey to list/restart VPN's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
CM=$(which cloudmonkey) | |
function usage() { | |
APP=$(basename $0) | |
echo "Usage: $APP -h | -l | -v | -r <vpn-id> | -a" | |
echo " -h = Show help" | |
echo " -l = List disconnected VPN's" | |
echo " -v = List all VPN's" | |
echo " -r <vpn-id> = Restart VPN with <vpn-id>" | |
echo " -a = Restart all disconnected VPN's" | |
exit 1 | |
} | |
if [ -z "$CM" ]; then | |
echo "Install cloudmonkey first" | |
exit 1 | |
fi | |
if [ $# -eq 0 ]; then | |
usage | |
fi | |
$CM set profile VPN | |
$CM set display table | |
while getopts ":hlvr:a" opt | |
do | |
case $opt in | |
h) usage | |
;; | |
l) $CM list vpnconnections filter=id,state,publicip,gateway,cidrlist | grep Disco | |
;; | |
v) $CM list vpnconnections filter=id,state,publicip,gateway,cidrlist | |
;; | |
r) $CM reset vpnconnection id=$OPTARG | |
;; | |
a) VPNS=$($CM list vpnconnections filter=id,state | grep Disco | awk -F'|' '{ print $3 }') | |
for VPN in $VPNS | |
do | |
$CM reset vpnconnection id=$VPN | |
done | |
;; | |
\?) echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) echo "Option -$OPTARG requires argument" >&2 | |
exit 1 | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment