How to use a linux expect script to enter answer a prompt for password

wblakenc picture wblakenc · Jun 20, 2013 · Viewed 11.4k times · Source

I am having some trouble writing a script that will launch my forticlient vpn command line client and send my password when it is prompted. Here is my code:

#!/usr/bin/expect -f
set loadme "./forticlientsslvpncli --server myvpnserver --vpnuser theuser
eval spawn $loadme
expect "Password for VPN: "
send "password\r"

However, it still prompts for the vpn password. I am sure it is something simple and I am pretty new to linux scripting, but any help would be greatly appreciated!

Thanks!

Answer

Gregory Motruk picture Gregory Motruk · Oct 13, 2013
#!/usr/bin/expect -f
set timeout -1
cd /usr/local/forticlientsslvpn
spawn ./forticlientsslvpn_cli --server myhost:10443 --vpnuser myuser
expect "Password for VPN:" {send -- "mypassword\r"}
expect "to this server? (Y/N)\r" {send -- "y\r"}

expect eof