Search code examples
cygwintclexpect

Cygwin issue with expect - spawn id exp64 not open


I have a problem, if I run a TCL/expect script from cygwin. When I'm getting the 64th session, I got the following error(debug output):

spawn ssh [email protected]
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {8972}

expect: does "" (spawn_id exp64) match glob pattern "unsuccessful login"? no
"Can't ping [email protected]! Quitting."? no
"refused"? no
"Bad IP address"? no
"computer name"? no
"Usage of telnet deprecated, instead use"? no
"Invalid input detected at"? no
"timed out"? no
"o route to host"? no
"closed"? no
"ermission denied"? no
"estination unreachable"? no
"imeout expired"? no
"(NO/YES)"? no
"continue connecting"? no
"Username: useri"? no
"ser:"? no
"sername:"? no
"assword:"? no

expect: does "" (spawn_id exp64) match glob pattern "useri@server%"? no
"useri@server:*%"? no
"useri@server>"? no
"useri@server"? no
"server "? no
"server\r"? no
"server>"? no
"server"? no

expect: does "" (spawn_id exp64) match glob pattern "@asd"? no
expect: read eof
expect: set expect_out(spawn_id) "exp64"
expect: set expect_out(buffer) ""
exp_i_parse_states: : spawn id exp64 not open: spawn id exp64 not open
    while executing
"expect {
      # Special cases, switch to different login
      -i $sid "unsuccessful login"  { exp_continue }
      -i $sid "Can't ping $Username@$Ho..."
    (procedure "connecthor" line 5)
    invoked from within
"connecthor $Servername($i) $Server($i) $Serveruser($i) $Serverpass($i) $Option $sid $Enablepass"
    (procedure "dialin" line 44)
    invoked from within
"dialin $Routername $L_user"
    ("-(checker)" arm line 31)
    invoked from within
"switch -regexp -nocase -- [lindex $argv 0] \
  -(initpass) {
    puts "\r\rThis is the initial password manager module of to script."
    puts "WARNIN..."
    (file "/usr/bin/to" line 366)

The script is working fine, doing it's job until it reaches the session exp64. I've also tried to run the script under Ubuntu natively instead of Cygwin. It was working fine, without any error.

I'm experiencing this issue with other scripts as well. I've already tried to re-install Cygwin, same issue appeared.

Do you maybe have an idea what could it be?


In the meantime:

Just wrote a minimal script, SSHing to a Cisco router, send a command, and exit out. It does the job in an endless loop, so I can log the $spawn_id in the meantime:

#!/usr/bin/expect
set i 1
while {1} {
    spawn ssh [email protected]
    set sid $spawn_id
    expect "assword:"
    send "Start123\r"
    expect "Router"
    send "show ip int brief\r"
    while {1} {
        expect {
            "Router" {send "exit\r"}
            eof {break}
        }
    }
    puts "*** Loop is running: $i, spawn_id is: $sid ***"
    incr i
}

I get the same error with this as well:

*** Loop is running: 60, spawn_id is: exp63 ***
spawn ssh [email protected]
send: spawn id exp64 not open

Solution

  • The problem is that you did not wait the exited ssh process. Without the wait, an exited ssh process would be showed as defunct which is still consuming the PID and maybe some FDs. You can try like this:

        while {1} {
            expect {
                "Router" {send "exit\r"}
    ->          eof { wait -nowait; break }
            }
        }
        puts "*** Loop is running: $i, spawn_id is: $sid ***"
        incr i
    

    or

        while {1} {
            expect {
                "Router" {send "exit\r"}
                eof { break }
            }
        }
    ->  wait -nowait
        puts "*** Loop is running: $i, spawn_id is: $sid ***"
        incr i