【发布时间】:2014-08-26 03:12:09
【问题描述】:
我有一个 telnet 到路由器并给出命令并记录输出的期望脚本。以下 sn-p 应该是理想的输出。
==========================================================================
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";是给定的命令 - 我需要该命令的输出。
【问题讨论】:
-
有趣;到损坏点的输出长度约为 1500 字节。我能想到的唯一与这类事情相关的是某种以太网数据包帧大小,或者可能是 MTU。 为什么这有关系? TCP 应该让我们免受这种事情的影响……
-
您最好通过将
terminal length设置为15 来解决此问题,并让您的expect 脚本知道如何处理分页。这将是一个丑陋的解决方法,但至少有可能…… -
在任何人问之前,我对 expect 细节的了解是不稳定的,我对 Cisco 路由器固件的了解完全不存在。我可以用谷歌搜索东西,但你也可以这样做。 (或者其他人可以通过正确的答案告诉你如何做到这一点。)
-
@DonalFellows:谢谢,我会试试你在第二条评论中说的那个。
-
@DonalFellows:确实有效。非常感谢。