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

时间:2015-01-08 00:46:49

标签: expect

在此问题被列为timeoutmax_match问题之前,我会说我已尝试过这些问题。我也尝试过使用full_buffer,但似乎唯一的解决方法是在sleep之后将expect置于大型输出之前。在终端可以打印输出之前,几乎就像期望看到并处理expect ">$"一样。

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

示例:

    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)
   }
   }

我能够解决此问题的唯一方法是在sleep之后添加expect ">$"(我在下面的简单脚本中执行了此操作,并且还在处理full_buffer的脚本中添加了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 ):

sleep

这有效,但有没有一种正确的方法来执行此操作,而不是让脚本等待expect -d?并非所有设备都具有如此大的输出,因此每台主机都不需要睡眠。

我做的另一个测试是使用tty_set: raw = 3, echo = 0 运行脚本,以下是截断的输出结束:

{{1}}

谢谢, 克里斯

1 个答案:

答案 0 :(得分: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的大输出并逐行打印。果然,输出停止了,脚本停止了。如果有人想深入研究这个问题,请告诉我,我很乐意提供更多信息。

相关问题