I have to re-login to my VPN every time I leave my desk, and it is tedious. I am trying to pass the shell the info but it doesn't get it in the right order. The order is "try to openconnect, enter sudo pw if needed, then username, then password". pexpect would be good, since it can tell if you need your sudo password or not, but isn't working:
#!/usr/bin/env python
# coding: utf-8
import os, sys, subprocess, time, re, pexpect
from my_scripting_library import *
child = pexpect.spawn('sudo openconnect vpn.com')
# send sudo pw
child.expect('.*')
child.sendline(sudopw)
# send sn
child.expect('.*')
child.sendline('cchilders')
# send work pw
child.expect('.*')
child.sendline(vpnpw)
time.sleep(150)
Here is what it looks like when I perform these steps manually:
cchilders:~/scripts/work_scripts [master]$ sudo openconnect vpn.com
[sudo] password for cchilders:
POST https://vpn.com
Attempting to connect to server 555.555.55.55:555
Please enter your username and password.
Username:
Password:
When I try to feed my sudo password by shell like I have before, the VPN times out and says
SSL negotiation with vpn.com
Server certificate verify failed: certificate does not match hostname
I use
alias vpn='echo $MYPW | sudo -S openconnect vpn.com'
How can I send my sudo password, then my username, then my VPN password all in a row from a shell/python script? Thank you