Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Created January 5, 2017 03:31
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save alecthegeek/62b340ecb1480326eee1a13252ea83bb to your computer and use it in GitHub Desktop.
Save alecthegeek/62b340ecb1480326eee1a13252ea83bb to your computer and use it in GitHub Desktop.
Start the CISCO VPN client from the command line
#!/usr/bin/env expect -f
# Start the CISCO VPN client on a Mac. Adapted from
# https://blog.felipe-alfaro.com/2014/05/23/automating-cisco-anyconnect-secure-mobility-client-on-mac-os-x/
set HOSTNAME vpn.server.com
set USER_NAME user.name
set PASSWORD password
spawn /opt/cisco/anyconnect/bin/vpn
expect {
"state: Connected" { send disconnect\n ; exp_continue; sleep 3 }
"state: Disconnected" {sleep 2;send "connect $HOSTNAME\n"}
}
expect -timeout 60 -re "Username: .+] "; send $USER_NAME\n
expect "Password: " ; send $PASSWORD\n
expect "state: Connected"; sleep 2; send exit\n
@aelhilali
Copy link

Hi there , possible to make it with zsh ?

@alecthegeek
Copy link
Author

alecthegeek commented Jun 16, 2021

No -- this is what expect is for. Zsh, or Bash etc would not be a suitable solution

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