I have an expect script that connects to a vpn using openconnect. The script works perfectly, except that I don't know how to keep openconnect alive once the password has been provided and expect has reached the EOF. I think I need to fork the process, but I need it to keep the password somehow. Here is my script
#!/usr/bin/expect -f
spawn ./openconnect
expect "sudo"
send "sudo_password\r"
expect "password:"
send "vpn_password\r"
expect /Connected\stun1\sas/ #expect connected tun1 as some ip
and openconnect
#!/usr/bin/env bash
sudo -k
sudo -S openconnect --juniper --user username --csd-wrapper ~/juniper-vpn-py/tnc vpn_server
The output gets to connected tun1 as some ip as expected, but then expect closes and so does the process is spawned.