8

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!

wblakenc
  • 464
  • 1
  • 5
  • 19
  • 3
    missing a closing quote in the `set loadme` line. Also, add `exp_internal 1` to the top of the script -- expect will show you if the password prompt is being matched. – glenn jackman Jun 20 '13 at 17:37
  • The missing closing quote was a typo on here, but thanks for pointing it out. Adding `exp_internal 1` (which is the same as `#!/var/bin/expect -d`) solved my problem. For those that might not know `-d` provides debugging output so I quickly realized the prompt was not being matched. I wish I could mark your answer as the correct, however I will up vote. Thanks! – wblakenc Jun 21 '13 at 13:13

4 Answers4

17
#!/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
kapex
  • 28,903
  • 6
  • 107
  • 121
Gregory Motruk
  • 171
  • 1
  • 3
4

From the comment I got from glenn jackman I was able to figure out that the password prompt was not being matched. I changed my first line to #!/var/bin/expect -d which provided the necessary debugging output to find out the problem and fix it.

Thanks Glenn!

wblakenc
  • 464
  • 1
  • 5
  • 19
1

Your code syntax could be wrong or given password could be wrong. So you can try it on expect prompt - line by line to debug it.

Senthil Murugan
  • 109
  • 1
  • 3
0

You may use forticlientsslvpn_cli with Expect to feed in the password.

A complete solution available here:

https://gist.github.com/azizasm/e216bc47b54f5b68405f3c8f8b832e8a

Note: this solution will auto reconnect the if the VPN get disconnected.

AzizSM
  • 6,199
  • 4
  • 42
  • 53