我对expect脚本是个新手。我正在尝试使用自动telnet脚本备份华为路由器配置。我被困在处理一个字符串“-更多-”,就像按任何键继续我想要发送的"\n“
我的路由器输出如下:
--------------------------------
-----------------------
voice-vlan mac-address 00d0-1e00-0000 mask ffff-ff00-0000 description Pingtel phone
voice-vlan mac-address 00e0-7500-0000 mask ffff-ff00-0000 description Polycom phone
voice-vlan mac-address 00e0-bb00-0000 mask ffff-ff00-0000 description 3com phone
#
---- More ----我的脚本是:
#!/usr/bin/expect
spawn telnet 192.168.xx.xx
expect "Username:"
send "username\n"
expect "Password:"
send "password\n"
expect ">"
# 'dis cur' is like cisco's 'show run'
send "dis cur\n"
expect "---- More ----"
send "\n"
interact在运行脚本终端时抛出以下错误:
bad flag "---- More ----": must be -glob, -regexp, -exact, -notransfer, -nocase, -i, -indices, -iread, -timestamp, -timeout, -nobrace, or --
while executing
"expect "---- More ----""有人能帮我解决这个问题吗?...提前感谢:)
发布于 2013-01-17 23:27:56
快速答案:将-ex放在以-开头的字符串前面,这样expect代码就可以肯定地知道它不是一个选项。
然而,除了快速回答之外,你还应该做一个稍微复杂一点的版本:
expect {
">" {
# Found prompt
}
-ex "---- More ----" {
send "\n" ;# Or maybe \r?
exp_continue ;# Keep on expecting please
}
}
interact这具有允许寻呼机输出零次、一次或多次的优点。
https://stackoverflow.com/questions/14381653
复制相似问题