hellojoshhhy
hellojoshhhy

Reputation: 958

Expect doesn't recognize command "timeout" in loop

I have an expect script to check login status, if console showing "poplar login", script will send username (no password) and wait 180s for system ready. Once system ready it will check is the console showing "root@poplar" if yes, it will break and send success message. If not, expect will be timeout and go back to "poplar login"

my script

set timeout 2 
expect {
            "poplar login" {
               send "root\r";
               sleep 180; send "\r" ;
               send "\r" ;
               exp_continue
            }
            "root@poplar"
            timeout { send "\r" ; exp_continue }
} 

send_user "login success!\n"

Somehow the timeout is always not read by expect and the log is like follow

 expect: does"\r\n\u001b[r\u001b[m\u001b[2J\u001b[H\u001b[?7h\u001b[?1;4;6l
 \u001b[?1049h\u001b[4l\u001b[?1h\u001b=\u001b[0m\u001b(B\u001b[1;70r\u001b[H
 \u001b[2J\u001b[H\u001b[2J"(spawn_id exp5) match glob pattern "poplar login"? no
 "root@poplar"? no 
 " send "\r" ; exp_continue "? no
 expect: timed out
 login success! 
 send: sending "reboot\r" to { exp5 }

Please assist, thanks

Upvotes: 0

Views: 239

Answers (1)

pynexj
pynexj

Reputation: 20688

Change

"root@poplar"
timeout { send "\r" ; exp_continue }

to

"root@poplar" {}
timeout { send "\r" ; exp_continue }

or it would be handled as

"root@poplar" timeout
{ send "\r" ; exp_continue }

That's why you see the debug message

" send "\r" ; exp_continue "? no

because the part { send "\r" ; exp_continue } is handled as a PATTERN.

Upvotes: 1

Related Questions