期望Cygwin问题 - spawn id exp64未打开

时间:2017-03-06 11:50:53

标签: cygwin tcl expect

如果我从cygwin运行TCL / expect脚本,我有一个问题。 当我第64次会议时,我收到以下错误(调试输出):

spawn ssh useri@1.1.1.1
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 useri@1.1.1.1! 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)

脚本工作正常,完成它的工作直到它达到exp64会话。我也试图在Ubuntu下本地运行脚本而不是Cygwin。它工作正常,没有任何错误。

我也遇到过其他脚本的问题。 我已经尝试重新安装Cygwin,同样的问题出现了。

你可能知道它会是什么?

与此同时:

刚写了一个最小的脚本,SSH连接到Cisco路由器,发送命令,然后退出。它在无限循环中完成工作,因此我可以在此期间记录$ spawn_id:

#!/usr/bin/expect
set i 1
while {1} {
    spawn ssh username@1.1.1.1
    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
}

我也得到同样的错误:

*** Loop is running: 60, spawn_id is: exp63 ***
spawn ssh username@1.1.1.1
send: spawn id exp64 not open

2 个答案:

答案 0 :(得分:2)

可以维持的同时期望会话数量有限制。该限制因操作系统而异,并且(至少在某些平台上)是全局限制,而不是进程本地限制。虽然您已经使用Windows,但您可能还会遇到每个进程限制;我不完全确定(虽然64听起来就像其中之一)。在任何情况下,听起来都像是在耗尽资源。

一旦你完成了与特定主机的互动,你还记得safe navigation operator吗?如果您在此过程中获得了许多旧的期望会话,那么您将会泄漏相当宝贵的资源。

答案 1 :(得分:0)

问题是您没有wait退出的ssh进程。如果没有wait,则退出的ssh流程将显示为defunct,但仍在使用PID,有些FDs。你可以尝试这样:

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

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