当expect_out(buffer) size的内部缓冲区大小超过时,如何从expect获得完整的输出



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

    proc SendCommands { Commands } {
            global prompt log errlog
                    foreach element [split $Commands ";"] {
                                    expect {
                                           -re $prompt
                                            {send -- "$elementr"}
                                           }
                                    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 promptn"; exit 1 }
      eof { send_user "nSSH failure for $hostn"; exit 1 }
           "*?assword:*"
          {
           send -- "$passwordr"
          }
    }

    expect {
              timeout { send_user "nLogin incorrectn"; exit 1 }
              eof { send_user "nSSH failure for $hostn"; 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时,我才得到完整的输出,但是当我在上面的函数sendcommands中使用puts命令时,我得到了大约90%的10%

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

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

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

经过一番搜索,我想出了这个,似乎工作,但让我知道任何异常或更好的答案:

设置match_max = 1000 then

    expect {
           -re $prompt
          {send -- "$elementr"}
    full_buffer {
        append outcome $expect_out(buffer)
        exp_continue
    }
                                    }
append outcome $expect_out(buffer)
puts $outcome

但是当我设置match_max = 10000或100时它仍然失败

最新更新