|
藍森林 http://www.lslnet.com 2006年6月26日 11:18
請教一個expect的問題
我想編寫腳本自動登錄到路由器,然後取出其中的配置
在腳本中使用send "show running \n「
但是sh running命令並沒有傳遞到路由器上,路由器上沒有命令顯示
是不是因為路由器的編碼格式和服務器不同呢
請問有沒有大老曾經做過類似的事情,應該如何解決,謝謝! |
請教一個expect的問題
-->
肯定不是,你寫錯了! |
請教一個expect的問題
剛才按照你的想法寫了幾行,你看看行不?
不過,這樣能取得到配置馬?
#!/usr/local/bin/expect --
eval spawn telnet 你的路由的地址
expect "*password:*"
send "你的密碼"
expect "*router>*"
send "en\n"
expect "password:"
send "你的超級密碼"
send "sh run\n"
interact
完 |
請教一個expect的問題
我有同樣的問題需要老大們幫助阿,
各位老大,我的腳本已經登陸到路由器了,在日誌中可以查看到命令執行到Router(config)#
send "configure terminal\r"
expect {
"Router(config)#" { }
default { err_exit "Feiled to enter ConfigureMode " }
}
send "router ospf 100\r"
expect {
"Router(config-router)#" { }
default { err_exit "Failed to enter ISIS_ConfigureMode " }
}
由於路由器上執行config t命令後路由器會多顯示了一行提示,
Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
所以我的腳本每次進入Router(config)#
模式後無法進行下面的router ospf 100
請教老大如何解決這個問題? |
請教一個expect的問題
:oops:
用一個循環等待期待的提示符出現.
for {} {1} {} {
set brk [ expr $goto + 1 ]
expect {
-re "#" {
if { $brk > 256 } {
break
}
send "router ospf 100\r"
}
} |
| |