Question

I need help creating a loop in expect. I have a script that spawns ssh into cisco router and does "show call active voice brief" command. I need to capture all of the output, but the problem is that when the screen is filled it stops and requires me to press space to see the rest of the output. The output is not always the same length. That means that the quantity of times I have to press space varies. This I what I need to loop>>>

expect “*More*” #this means the screen is full and I need to press space to see more output

send – “ “

So How do i loop this.

expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
expect "*More*" {send " "} \
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
Was it helpful?

Solution

Like this:

expect {
    "*More*" {send " "; exp_continue} 
    "*RTsedeVoIP_GW1#*" {send -- "exit\r"}
}

The exp_continue command is essentially a "redo" to loop within the current expect command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top