アプライアンスにログインして構成を取得し、ファイルに書き込むことを期待して使用しようとしています (ssh キーを使用できず、アプライアンスはそれをサポートしておらず、実際には 2 つのログインがあります)。
問題は、これを使用すると、データが切り捨てられることです (構成ファイルの最後の ~100 行しか取得しません)。
...snip...
match_max 100000
set timeout 150
set output [open "outputfile.txt" "w"]
set config $expect_out(buffer)
puts $output $config
close $output
...snip...
だから今、どこかで読んだ提案に従って、一度に1行ずつ出力をループするためにexpectを使用しようとしていますが、ループなしでできるようにデータを出力することはできません。これが機能していないコードです。構成は〜700行です。
#!/usr/bin/expect
match_max 50000
spawn ssh admin@192.168.1.10
expect "password"
send "password1\r"
expect "user"
send "root\r"
expect "password"
send "password2\r"
set outcome {}
set writeout [open "outputfile.txt" "w"]
expect "device"
exp_send "show running\r"
expect {
-regexp {.*}{
set outcome "${outcome}$expect_out(0,string)"
exp_continue
}
}
puts $writeout $outcome
close $writeout
expect "device"
send "exit\r"
send "yes\r"
どんな助けでも大歓迎です。さらに情報が必要な場合はお知らせください。
ありがとう!