繁体   English   中英

当expect_out(缓冲区)大小的内部缓冲区大小超过时,如何从期望中获得完整的输出?

[英]How to get the complete output from expect when the internal buffer size of expect_out(buffer) size exceeds?

我不知道发生了什么,但我没有从执行的远程命令获得完整的输出可能因为期望内部缓冲区被执行。

    proc SendCommands { Commands } {
            global prompt log errlog
                    foreach element [split $Commands ";"] {
                                    expect {
                                           -re $prompt
                                            {send -- "$element\r"}
                                           }
                                    set outcome "$expect_out(buffer)"
                             foreach line [split $outcome \n] {
                                       foreach word [regexp -all -inline {\S+} $line] {

                                            if {( [string index [string trimleft $line " "] 0 ] == "%")} {
                                              puts  "$outcome"
                                               exit 1
                                            }
                                      }
                            }
                    puts "$outcome"
                   }

    }

    set timeout 30

    foreach  host [ split $hosts "\;" ] {
            spawn ssh -o "StrictHostKeyChecking no" "$username@$host"
    match_max   10000000

    expect {
      timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
      eof { send_user "\nSSH failure for $host\n"; exit 1 }
           "*?assword:*"
          {
           send -- "$password\r"
          }

    }


    expect {
              timeout { send_user "\nLogin incorrect\n"; exit 1 }
              eof { send_user "\nSSH failure for $host\n"; exit 1 }

         -re  "$prompt"
           { send -- "\r" }
           }
    set timeout 300
    SendCommands "$Commands"
    }

这就是我执行它的方式:

./sendcommand aehj SWEs-elmPCI-B-01.tellus comnet1 "terminal length 0;show int description" "(.*#)$"

我只有当我删除log user 0时才获得完整的输出,但是当我在上面的fucnction sendcommands中使用puts命令时,我得到了大约90%的结果,最后10%的尾随数据没有显示。

我想的一种方法是在期望中使用正则表达式的否定但它似乎不起作用。

                                    expect {
                                           -re ! $prompt
                                            {puts $expect_outcome(buffer)}
                                           }

编辑:当执行约5或7次时,我获得所有输出一次

经过一番搜索,我提出了这个并且似乎有效,但让我知道任何行为或更好的答案:

然后我设置match_max = 1000

    expect {
           -re $prompt
          {send -- "$element\r"}

    full_buffer {
        append outcome $expect_out(buffer)
        exp_continue
    }

                                    }
append outcome $expect_out(buffer)
puts $outcome

但是当我设置match_max = 10000或100时,它再次失败

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM