【问题标题】:expect telnet script : can't handle "----More---" string期望 telnet 脚本:无法处理“----More---”字符串
【发布时间】:2013-01-01 03:27:18
【问题描述】:

我是新的期望脚本。我正在尝试使用自动 telnet 脚本备份华为路由器配置。我一直在处理一个字符串“---More---”,就像按任意键继续我想发送“\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 ----""

谁能帮忙解决这个问题?...在​​此先感谢 :)

【问题讨论】:

  • 它没有一次滚动页面的选项..

标签: linux tcl telnet expect


【解决方案1】:

快速回答:将-ex 放在以- 开头的字符串前面,以便期望代码可以确定它不是一个选项。

但是,除了快速回答之外,您还应该做一个更复杂的版本:

expect {
    ">" {
        # Found prompt
    }
    -ex "---- More ----" {
        send "\n"    ;# Or maybe \r?
        exp_continue ;# Keep on expecting please
    }
}
interact

这具有允许寻呼机输出出现零次、一次或多次的优点。

【讨论】:

  • -ex 的意思是“这是一个精确的字符串”。
猜你喜欢
  • 1970-01-01
  • 2013-01-19
  • 2014-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 1970-01-01
  • 2017-05-02
相关资源
最近更新 更多