telnet expect script error 
Author Message
 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



Sat, 03 May 2008 07:10:46 GMT  
 telnet expect script error

Quote:

> 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



Sat, 03 May 2008 13:03:48 GMT  
 telnet expect script error
1. Why "Connection closed by foreign host." occur sometimes in the
telnet process?

I set
disable         = no
in
/etc/xinetd.d/telnet

I start telnet by:
# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

# telnet localhost
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: wireless
Password:
Last login: Mon Nov 14 16:15:47 from wireless1

2. I add an "expect_before eof {action}" as follows (after the process
is spawned) but got an error.

proc info_print { str} {
     puts "
++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    puts "              $str"
    puts  "
++++++++++++++++++++++++++++++++++++++++++++++++++++++"

Quote:
}

    exp_internal 1

    set res [spawn telnet $server]
    expect_before {
       -i $any_spawn_id  eof {
            info_print "eof"
            exit
       }
    }

    expect "login:" { send "$user\r" }
    expect "Password:" { send "$pass\r" }

    expect  {
        "Last login"  {
            info_print " "
            info_print "..Connected ! "
            sleep 0.5
        }
        "Login failed"  {
            info_print "**FAILED**  to TELNET to $server using ($user,$pass) "
            exit
        }
    }

------------------------
ERROR INFO:
can't read "any_spawn_id": no such variable
    while executing
"expect_before {
       -i $any_spawn_id  eof {
            info_print "eof"
            exit
       }
    }"
    (procedure "run_remote" line 16)
...........



Sat, 03 May 2008 22:58:01 GMT  
 telnet expect script error
"telnet localhost" always work manually in machine 1.
The expect script to automate telnet does not work in machine 1 but
always work in  machine 2.

"disable = no" is set in
/etc/xinetd.d/telnet

Use xinetd  to start telnet
$ /etc/init.d/xinetd restart

Script:
#!/usr/bin/expect

proc info_print { str} {
    send_user "
++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    send_user "              $str"
    send_user "
++++++++++++++++++++++++++++++++++++++++++++++++++++++"

Quote:
}

proc run_remote  { {server} {user} {pass} {params} } {
    set timeout 600
    set res [spawn telnet $server]
    expect "login:" { send "$user\r" }
    expect "Password:" { send "$pass\r" }

    expect  {
        "Last login"  {
            info_print " "
            info_print "..Connected ! "
            sleep 0.5
        }
        "Login failed"  {
            info_print "**FAILED**  to TELNET to $server using ($user,$pass) "
            exit
        }
    }

    info_print "sudo $params"
    send "sudo $params\r"
    expect {
        "Capturing" {
            info_print "Starting capture .. "
            expect {

            }
        }
    }

Quote:
}

run_remote  localhost john john "/usr/sbin/tethereal -i ath0 -c 1 -w
/tmp/sniff.capture"

#end script

$ ./telnet.exp
spawn telnet localhost
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Fedora Core release 3 (Heidelberg)
Kernel 2.6.9-1.667 on an i686
login: john
Connection closed by foreign host.
expect: spawn id exp5 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 12)
    invoked from within
"run_remote  localhost nexthop nexthop "/usr/sbin/tethereal -i ath0 -c
1 -w /tmp/sniff.capture""
    (file "./telnet.exp" line 49)



Sun, 04 May 2008 07:03:56 GMT  
 telnet expect script error

Quote:

> 1. Why "Connection closed by foreign host." occur sometimes in the
> telnet process?

> I set
> disable         = no
> in
> /etc/xinetd.d/telnet

> I start telnet by:
> # /etc/init.d/xinetd restart
> Stopping xinetd:                                           [  OK  ]
> Starting xinetd:                                           [  OK  ]

> # telnet localhost
> 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: wireless
> Password:
> Last login: Mon Nov 14 16:15:47 from wireless1

> 2. I add an "expect_before eof {action}" as follows (after the process
> is spawned) but got an error.

> proc info_print { str} {
>      puts "
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++"
>     puts "              $str"
>     puts  "
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++"
> }

>     exp_internal 1

>     set res [spawn telnet $server]
>     expect_before {
>        -i $any_spawn_id  eof {
>        info_print "eof"
>             exit
>        }
>     }

>     expect "login:" { send "$user\r" }
>     expect "Password:" { send "$pass\r" }

>     expect  {
>    "Last login"  {
>        info_print " "
>        info_print "..Connected ! "
>        sleep 0.5
>    }
>    "Login failed"  {
>        info_print "**FAILED**  to TELNET to $server using ($user,$pass) "
>        exit
>    }
>     }

> ------------------------
> ERROR INFO:
> can't read "any_spawn_id": no such variable
>     while executing
> "expect_before {
>        -i $any_spawn_id  eof {
>        info_print "eof"
>             exit
>        }
>     }"
>     (procedure "run_remote" line 16)
> ...........

any_spawn_id is a global.  If you're referencing it inside of a proc,
add a :: before it ($::any_spawn_id).

Don



Mon, 05 May 2008 01:14:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. expect to telnet and running and unknow script

2. expect telnet script, connect to hosts in a text file

3. Expect script changing telnet escape using `set escape ^\` problem

4. telnet expect scripts

5. Expect Script/Telnet Hangs

6. Expect: telnet scripts and primer

7. Operations on log_file before end-of-expect (spawn telnet)-script

8. How to make telnet script invisible -tcl/expect??

9. expect: telnet within telnet

10. Expect Telnet Error Handle?

11. Please HELP: spawn telnet error in Expect

12. Starting Multiple Expect Scripts from a Single Expect Script

 

 
Powered by phpBB® Forum Software