Skip to content

Instantly share code, notes, and snippets.

@sanderv32
Created Feb 1, 2017
Embed
What would you like to do?
Example of how to use CloudMonkey to list/restart VPN's
#!/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