2

I have the following expect script:

#!/usr/bin/expect

set timeout 20

set cmd "/path/vpntool  --server 1.2.3.4:443 --vpnuser user"
set password [lindex $argv 0]

eval spawn $cmd
expect "VPN:"
send "$password\r";
interact

expect ".*\(Y\/N\)"
send "Y\r";

interact

The scripts stops at the question "Would you like to connect to this server? (Y/N)" waits for the answer.

Does anybody know what could be the problem?

  • Error: “Would you like to connect to this server? (Y/N)” not found in script. I assume that it comes from an external command. Therefore you will have to give us some more information. – ctrl-alt-delor Feb 07 '19 at 11:30
  • The question comes from /path/vpntool binary which the Forticlient SSL VPN client. The second question comes on stdout only after the first value(password) is accepted. And it it usually comes with an delay smaller than 1 sec . I've also tried with "Would you like to connect to this server? (Y/N)" instead of the regex, and still doesn't work... – Spike.WD Feb 07 '19 at 11:59
  • I note you escaped the /. Is that the cause? OR maybe you need to send Y\n. – ctrl-alt-delor Feb 07 '19 at 12:05
  • After the password is accepted an expired certificate infos are dumped on stdout and the last line is "Would you like to connect to this server? (Y/N)" ... Maybe it could be a problem the fact that the question contains many lines... – Spike.WD Feb 07 '19 at 12:48
  • Is there a reason that you have an interact before your second expect command? That interact doesn't have a return condition, so the expect ".*\(Y\/N\)" is never reached... Also: the / character isn't special to regular expressions and doesn't need to be escaped, and the .* at the beginning of the expect pattern is extraneous. – This isn't my real name Feb 07 '19 at 17:00

1 Answers1

5

Expect is doing exactly as you've told it to do.

You have the interact command without an exit criteria, so at that point the script gives control to the user and never takes it back.

If you need interactive access in the middle of an Expect script, see this question in Stack Overflow.SE. There are multiple answers that might be applicable, depending on exactly how you wish the script to behave.

If the script is supposed to be fully automated with no user interaction after starting the script, then why is the interact command there?

telcoM
  • 96,466
  • Expect is doing exactly as you've told it to do thanks for checking that there's no bug in expect. – Eric Oct 14 '19 at 16:12