我想使用期望登錄的設備,獲取配置,並將其寫入一個文件(我不能使用SSH密鑰,設備不支持,而事實上有兩個登錄)。使用期望遍歷輸出發送到文件
的問題是,當我用這個,數據被截斷(我只得到了配置文件的最後〜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...
所以現在,每一個建議,我在其他地方見過,我是試圖使用期望來循環輸出,一次一行,但我無法像沒有循環一樣獲得數據輸出。這裏是不工作的代碼。配置是〜700行。
#!/usr/bin/expect
match_max 50000
spawn ssh [email protected]
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"
任何幫助將不勝感激。讓我知道你是否需要更多信息。
謝謝!