Having trouble using expect to launch vpn program

Hello all.

I am a linux and linux scripting newbie so please forgive my ignorance. I have been tasked to write what I thought should be a pretty simple script that does the following:
1) Loads our forticlient ssl vpn command line client
2) sends the vpn password to the client

Pretty simple. However I am having trouble getting following code to work:

#!/usr/bin/expect -d
set pw "test"
eval spawn ./forticlientsslvpn_cli --server vpnserver --vpnuser theuser
expect "Password for VPN:"
send "$pw\r"

A couple of things, yes I know that having the password as clear text not a good idea. I am just trying to get this to work.

Second, I know that the -d in the first line provides debugging info. I am not sure if this is the cause of my trouble, however when I use -f when the script is run, I still see the prompt for the password and the program pauses like it is waiting for my input. At least with -d I can see a little bit of what is going on, and it looks like it should work.

Suggestions? I am lost and a bit over my head.

I write most of my expect using a trial run under 'autoexpect'. Then I do not need to know expect or tcl.

1 Like

Autoexpect works nicely, plus it wrote a working script for me to take a look at and figure out what I was doing wrong. I think the main problem was timing. There were a few commands I was missing as well.

Thank you!

Will