telnet expect script error



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

.



Relevant Pages

  • Re: telnet expect script error
    ... > This is my expect script to telnet. ... > it fail. ... > set timeout -1 ...
    (comp.lang.tcl)
  • Re: A few questions, if somebody could please assist -ive been doing my head in to get my vba pr
    ... Dim c As String, wdth As Double ... as for telnet, I would look for a telnet program that can be scripted. ... spreadsheet the userform i have made runs from. ... script files like the ftp does and any telnt code i have seen has lost me ...
    (microsoft.public.excel.programming)
  • SOLUTION: Keeping Telnet Session Open
    ... After more tinkering with my expect script, ... > Thanks to several people for responding. ... > see the telnet running in the psoutput. ... > the other end is accepting the connection. ...
    (SunManagers)
  • Really weird expect problem
    ... I'm working on a legacy expect script. ... At first glance it would seem that the shell is in echo or verbose mode, ... is operating telnet from a Windows 2000 machine. ... I've looked for strange environment variables. ...
    (comp.unix.programmer)
  • Re: Script for telnet server to communicate with J2EE application
    ... Is there any way that this script automatically get invoked as the ... Telnet Client login to Server? ... As you were asking about using telnet client classes to allow your Java application to talk to a telnet server, I was assuming you'd want to use something like the following to login, send one barcode to the telnet server and logout again: ...
    (comp.lang.java.programmer)