Cygwin 问题与 expect - spawn id exp64 未打开

Cygwin issue with expect - spawn id exp64 not open

我有一个问题,如果我 运行 来自 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

可以同时维护的预期会话数有限制。该限制因 OS 而异,并且(至少在某些平台上)是 全局限制 ,而不是进程本地限制。尽管由于您在 Windows,您可能还会遇到每个进程的限制;我不完全确定(虽然 64 听起来完全像其中之一)。无论如何,这听起来像是资源耗尽。

您是否记得在完成与特定主机的交互后close?如果您在此过程中有很多旧的 expect 会话,您将泄漏非常宝贵的资源池。

问题是你没有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