Skip to content

Instantly share code, notes, and snippets.

@rhowe-gds
Last active June 4, 2019 15:44
Show Gist options
  • Save rhowe-gds/dda45cd739cc2f324b3e656f9f76a312 to your computer and use it in GitHub Desktop.
Save rhowe-gds/dda45cd739cc2f324b3e656f9f76a312 to your computer and use it in GitHub Desktop.
VPN connection script
#!/usr/bin/env bash
set -euo pipefail
usage="$0: <up|down> [connection name]"
action="${1?$usage}"
connection="${2:-GDS VPN Developer}"
oath_key=vpn
pass_key=gds/vpn
case "$action" in
up)
otp=$(ykman oath code "$oath_key" | awk '/[0-9]$/ { print $NF; }')
: "${otp:?OTP not found}"
password=$(pass "$pass_key")
# Shut down the GUI app, which doesn't get along with the CLI tool
pkill "Cisco AnyConnect Secure Mobility Client" || :
echo -e "${USER}\n${password}\n${otp}" | \
/opt/cisco/anyconnect/bin/vpn -s connect "$connection" | \
grep --line-buffered -Fv 'Second Password'
;;
down)
/opt/cisco/anyconnect/bin/vpn -s disconnect
;;
*)
echo "$usage" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment