Rousseau
Rousseau

Reputation: 85

expect telnet script : can't handle "----More---" string

I am new with expect scripting. I'm trying to backup Huawei router configuration with automated telnet script. I'm stuck in handling one string "---More---", it's like press any key to continue where I would like to send "\n"

My router output is like:

--------------------------------
-----------------------
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 ----

And My Script is :

#!/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

While running the script terminal throwing me this error:

  bad flag "---- More ----": must be -glob, -regexp, -exact, -notransfer, -nocase, -i,      -indices, -iread, -timestamp, -timeout, -nobrace, or --
while executing
"expect "---- More ----""

Can anyone help fixing this?... Thanks in advance :)

Upvotes: 0

Views: 5287

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

Quick answer: put -ex in front of the string that starts with a - so that the expect code can know for sure that it isn't an option.

However, aside from the quick answer you should do a somewhat more sophisticated version:

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

This has the advantage of allowing zero, one or many occurrences of the pager output.

Upvotes: 3

Related Questions