期望不等待提示 - 脚本停止而不发送其他命令

Expect not waiting for prompt - script stops without sending other commands

在将其记为 timeoutmax_match 问题之前,我会说我已经尝试过这些问题。我也尝试过使用 full_buffer,但似乎唯一的解决办法是在 expect 之后放置一个 sleep,当它前面有大量输出时。就好像 expect ">$" 在终端可以打印输出之前被 expect 看到并处理了。

term len 0是一个cisco命令,基本上防止文件默认| more

示例:

    set timeout -1
    spawn ssh host
    expect "assword:"
    send "$pass\r"
    expect ">$"
    send "term len 0\r"
    expect ">$"
    set size_orig [match_max]
    match_max 60000000
    send "show start\r"
    expect ">$"

不起作用。 "show start" 的输出在输出中停止了 x 行。

如果我对 timeoutfull_buffer 进行处理,同样的事情会发生:

    set timeout -1
    spawn ssh host
    expect "assword:"
    send "$pass\r"
    expect ">$"
    send "term len 0\r"
    expect ">$"
    set size_orig [match_max]
    match_max 60000000
    set timeout -1
    send "show start\r"
    expect {
           timeout {
                   send $expect_out(buffer)
           }
           full_buffer {
                   send $expect_out(buffer)
           }

           ">$" {
           append outcome $expect_out(buffer)
   }
   }

我能够解决这个问题的唯一方法是在 expect ">$" 之后添加一个 sleep(我在下面的简单脚本中以及处理 [=6= 的脚本中都这样做了) ] 和 timeout) :

    set timeout -1
    spawn ssh host
    expect "assword:"
    send "$pass\r"
    expect ">$"
    send "term len 0\r"
    expect ">$"
    set size_orig [match_max]
    match_max 60000000
    set timeout -1
    send "show start\r"
    expect ">$"
    sleep 10

这行得通,但是有没有正确的方法来执行此操作而不是让脚本等待 sleeping?并非所有设备都有如此大的输出,因此每个主机都不需要睡眠。

我做的另一个测试是使用 expect -d 运行脚本,以下是截断输出的末尾:

tty_set: raw = 3, echo = 0

谢谢, 克里斯

以下通过抑制向用户显示的输出解决了我的脚本中的问题,而是将其附加到我的 log_file :

log_file -a initial_commands
log_user 0
send "some commands with large output"
log_file
log_user 1

在这种情况下,用户是否看到输出并不重要,因为我正在解析它并将其输出到文件中。为了进一步证明这是我的 expect "<$" 代码中的一个错误,我在 运行 system "parse.pl" 时遇到了同样的行为(完全是偶然的)。该 perl 脚本只是读取 show start 的大量输出并逐行打印出来。果然,输出突然停止了,脚本也停止了。如果有人想更深入地研究这个问题,请告诉我,我很乐意提供更多信息。