-
-
Save LeePorte/b812f2c571f37c2429af623c89b41746 to your computer and use it in GitHub Desktop.
Cisco Anyconnect cli script
This file contains hidden or 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 | |
set -euo pipefail | |
usage="$0: <up|down|state|stats> [connection name]" | |
action="${1?$usage}" | |
connection="${2:-GDS VPN Developer}" | |
oath_key=gds-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 | |
;; | |
state) | |
/opt/cisco/anyconnect/bin/vpn state | |
;; | |
stats) | |
/opt/cisco/anyconnect/bin/vpn stats | |
;; | |
*) | |
echo "$usage" >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment