我有一个期望脚本telnet到路由器并提供命令并记录输出。以下代码段应该是理想的输出。
==========================================================================
slot type number number rev. addresses
---- ------------------ ---------- ---------- -------- ---------
0/0 GE-4 IOA 4306297694 4500006802 A04 4
0/1 --- --- --- --- ---
1/0 GE-4 IOA 4306255468 4500006802 A04 4
1/1 --- --- --- --- ---
2/0 GE-8 IOA 4306211660 4500009102 A05 8
2/1 --- --- --- --- ---
3/0 --- --- --- --- ---
3/1 --- --- --- --- ---
4/0 --- --- --- --- ---
4/1 --- --- --- --- ---
5/0 OC3/STM1-8 ATM IOA 4305503226 4500006903 A02
5/1 --- --- --- --- ---
7/0 SRP IOA 4306297292 4501006502 A00 2
11/0 Service IOA 4306516819 4501007103 A00
11/1 --- --- --- --- ---
12/0 --- --- --- --- ---
12/1 --- --- --- --- ---
13/0 GE-4 IOA 4306255468 4500006802 A04 4
13/1 --- --- --- --- ---
14/1 --- --- --- --- ---
15/0 --- --- --- --- ---
15/1 --- --- --- --- ---
==========================================================================
但我得到的是这个... 13/0线路已损坏且13/1完全丢失且这是相当一致的 - 只有这些线路被破坏。我已将match_max设置为60000.我甚至在发送命令后添加了“sleep 10”。
==========================================================================
slot type number number rev. addresses
---- ------------------ ---------- ---------- -------- ---------
0/0 GE-4 IOA 4306297694 4500006802 A04 4
0/1 --- --- --- --- ---
1/0 GE-4 IOA 4306255468 4500006802 A04 4
1/1 --- --- --- --- ---
2/0 GE-8 IOA 4306211660 4500009102 A05 8
2/1 --- --- --- --- ---
3/0 --- --- --- --- ---
3/1 --- --- --- --- ---
4/0 --- --- --- --- ---
4/1 --- --- --- --- ---
5/0 OC3/STM1-8 ATM IOA 4305503226 4500006903 A02
5/1 --- --- --- --- ---
7/0 SRP IOA 4306297292 4501006502 A00 2
11/0 Service IOA 4306516819 4501007103 A00
11/1 --- --- --- --- ---
12/0 --- --- --- --- ---
12/1 --- --- --- --- ---
13/0 G ---
14/1 --- --- --- --- ---
15/0 --- --- --- --- ---
15/1 --- --- --- --- ---
==========================================================================
无法弄清楚为什么会这样。
这是代码
if {[info exists router_name]} {
spawn telnet $router_name
sleep 3
} else {
return "Spawner<< No router_name\n"
}
##newly added
expect -re ".*>|.*#" {
exp_send "term len 0\n"
puts "issuing show hard"
expect -re ".*>|.*#" {
exp_send "show hard\n"
}
#sleep 10
#puts "issuing newlines"
expect -re ".*>|.*#" { exp_send "exit\n\n\n\n" }
} -re ".*login.*|.*name.*" {
if {[info exists router_username]} {
exp_send "$router_username\n"
}
exp_continue
} -re ".*word*" {
if {[info exists router_pass]} {
exp_send "$router_pass\n"
}
exp_continue
}
expect -re ".*" {}
close
行exp_send“show hardware \ n”;是给定的命令 - 我需要该命令的输出。
答案 0 :(得分:0)
正如@DonalFellows建议的那样 - 做好解决方法就完成了这项工作。
添加一个段以检测“--More--”并发送“\ n \ n”,接收输出而不会中断。
这是更改后的代码
if {[info exists router_name]} {
spawn telnet $router_name
sleep 3
} else {
return "Spawner<< No router_name\n"
}
expect -re ".*>|.*#" {
exp_send "term len 0\n"
puts "issuing show hard"
expect -re ".*>|.*#" {
exp_send "show hard\n"
}
#sleep 10
expect -re ".*>|.*#" {
exp_send "exit\n\n\n\n"
} -re ".*--More--.*" {
exp_send "\n\n"
}
} -re ".*login.*|.*name.*" {
if {[info exists router_username]} {
exp_send "$router_username\n"
}
exp_continue
} -re ".*word*" {
if {[info exists router_pass]} {
exp_send "$router_pass\n"
}
exp_continue
}
expect -re ".*" {}
close