Mokebe
Mokebe

Reputation: 23

expect telnet - command not executing

I am struggling with executing command via telnet/expect.

set send_slow {500 .5}
send -s -- "show slot *\r"
expect {
    ".*>" {
        send -s -- "y\r"
        exp_continue
    }
    ".*#\s"
}
send -s "who\r"
expect "# "
send -s "alm\r"
expect "# "
send -s -- "logout\r"

show slot command prints card in slots. Due to paging user is asked to continue. After execution that a prompt NODE2-1# is shown and I want to execute command who.

What I get is:

2/36 PF                   Empty                Up      Down    UEQ
2/37 FAN                  FAN                  Up      Up
2/38 Empty                Empty                Down    Down    UAS UEQ
2/39 Empty                Empty                Down    Down    UAS UEQ
25/1 SFD40                SFD40                Up      Up

Node2-1#<br> Node2-1# who

Session          Username                          Date         Terminal
-------------------------------------------------------------------------------
116 (cli tel) *  admin                             May 29 06:57 XX.X.XX.XX

Node2-1# almlogout

Alarm Status:  Critical-3    Major-0    Minor-0

As you can see, first prompt is left empty and in second one there is a command. It takes few seconds to execute it.

Moreover, below one can see, that in prompt there is pasted command almlogout. These two are separate commands -> alm and logout. However, they are pasted together.

Question is - how to execute command in prompt without that delay, and second - how to separate two commands

Upvotes: 1

Views: 170

Answers (1)

pynexj
pynexj

Reputation: 20688

By default, expect statement's pattern is in glob style so ".*>" should be -re ".*>" and ".*#\s" should be -re ".*#\\s" or -re {.*#\s} ("\s" is actually "s").

And since .* can match nothing, so -re {.*>} is the same as -re {>} and -re {.*#\s} the same as -re {#\s}.

Upvotes: 2

Related Questions