Re: telnet expect script error



"powah" <wong_powah@xxxxxxxx> writes:

> This is my expect script to telnet. Sometimes it works and sometimes
> it fail.
> Why and how to fix it?
>
> set timeout -1
>
> exp_internal 1
>
> set res [spawn telnet $server]
> expect "login:" { send "$user\r" }
> expect "Password:" { send "$pass\r" }
>
> expect {
> "Last login" {
> puts "..Connected ! "
> sleep 0.5
> }
> "Login failed" {
> puts "**FAILED** to TELNET to $server using ($user,$pass) "
> exit
> }
> }
>
> When the script fails, the error message is:
>
> Trying 127.0.0.1...
>
>
> Connected to localhost.localdomain (127.0.0.1).
>
>
> Escape character is '^]'.
>
>
> Fedora Core release 3 (Heidelberg)
>
> Kernel 2.6.9-1.667 on an i686
>
> login: john
>
> Connection closed by foreign host.
>
>
> ERROR INFO:
> expect: spawn id exp6 not open
> while executing
> "expect -nobrace {Last login} {
> info_print " "
> info_print "..Connected ! "
> sleep 0.5
> } {Login failed} {
> info_print "**FAILED** ..."
> invoked from within
> "expect {
> "Last login" {
> info_print " "
> info_print "..Connected ! "
> sleep 0.5
> }
> "Login failed" {
> info_print "**FAILED** to..."
> (procedure "run_remote" line 26)
> invoked from within

I assume that script excerpt is not the actual script generating the
error since the diagnostic makes reference to things like "info_print"
which is nowhere in evidence in your excerpt! With that in mind, I
can only make an educated guess - that the spawned process
occasionally exits prematurely. You can match that using the special
"eof" pattern. Add an "expect_before eof {action}" (after the process
is spawned, please) and you can match the eof no matter where it
occurs.

Don

.



Relevant Pages