As title says, trying to connect vpn via bash. The following script seemed closest to the answer I'm looking for:
#!/bin/bash
/opt/cisco/anyconnect/bin/vpn -s << EOF
connect https://your.cisco.vpn.hostname/vpn_name
here_goes_your_username
here_goes_your_passwordy
EOF
When I run this the vpn starts but then exits without an error and without connecting. This seems to be caused by the -s. If I remove this parameter the VPN will start but none of the commands (ie connect vpn, username, password) will be entered. From what I read the -s option will allow the username/password to be passed. Help!
c# solution ... in this case profile is the group name.
Although
expect
can be cleaner, it is not strictly necessary. Assuming/opt/cisco/anyconnect/bin/vpnagentd
is running as it automatically should be:To connect:
Replace
USERNAME
,PASSWORD
, andHOST
. The\ny
at the end is to accept the login banner - this is specific to my host, and so you may not need it.I understand that there are obvious security concerns with this method; it's for illustration purposes only.
To get state:
To disconnect:
This was tested with AnyConnect v3.1.05160.
I had to download the expect packages (yum install expect). Here is the code I used to automate vpn connection
Real easy! :D