何が起こっているのかわかりませんが、実行されたリモートコマンドから完全な出力が得られません。おそらく、内部バッファーが実行されていると予想されるためです。
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
られますが、上記の関数 sendcommands で puts コマンドを使用すると、その約 90% が得られ、最後の末尾のデータの 10% は表示されません。
私が考えている1つの方法は、expectで正規表現の否定を使用することですが、うまくいかないようです。
expect {
-re ! $prompt
{puts $expect_outcome(buffer)}
}
編集:約5回または7回実行すると、すべての出力が1回取得されます