0

私はexpectスクリプトを初めて使用します。自動化されたtelnetスクリプトを使用してHuaweiルーター構成をバックアップしようとしています。1つの文字列「---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 ----""

誰かがこれを修正するのを手伝ってもらえますか?...事前に感謝します:)

4

1 に答える 1

3

クイックアンサー:-exで始まる文字列の前に配置し-て、expectコードがオプションではないことを確実に認識できるようにします。

ただし、簡単な答えは別として、もう少し洗練されたバージョンを実行する必要があります。

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

これには、ポケットベル出力の発生を0回、1回、または多数許可できるという利点があります。

于 2013-01-17T15:27:56.090 に答える