Discussion:
[rancid] Problem with custom device script
Brian Talley
2011-04-08 20:25:07 UTC
Permalink
I'm creating a custom login script for a Crescendo load balancer device. I
can log in to the device and get to interactive mode ok using the script,
but when I try to run commands with something like:

crescendologin -d -t 30 -c"show running" host

it appears that expect is trying to match on every character with output
like:

...
send: sending "show running\r" to { exp6 }

expect: does "" (spawn_id exp6) match regular expression "^[^\n\r]*root> "?
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no

expect: does "s" (spawn_id exp6) match regular expression "^[^\n\r]*root> "?
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no
expect: timed out

Error: TIMEOUT reached

I feel like I'm missing something obvious. The pertinent section of
run_commands looks like:

for {set i 0} {$i < $num_commands} { incr i} {
send -- "[subst -nocommands [lindex $commands $i]]\r"
expect {
-re "^\[^\n\r]*$reprompt" { exp_continue }
-re "^\[^\n\r *]*$reprompt" {}
-re "\[\n\r]" { exp_continue }
}
}

And the actual prompt is "root> "

Thanks for any help.

BT
john heasley
2011-04-09 17:59:50 UTC
Permalink
Post by Brian Talley
I'm creating a custom login script for a Crescendo load balancer device. I
can log in to the device and get to interactive mode ok using the script,
crescendologin -d -t 30 -c"show running" host
it appears that expect is trying to match on every character with output
...
send: sending "show running\r" to { exp6 }
expect: does "" (spawn_id exp6) match regular expression "^[^\n\r]*root> "?
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no
expect: does "s" (spawn_id exp6) match regular expression "^[^\n\r]*root> "?
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no
expect: timed out
Error: TIMEOUT reached
I feel like I'm missing something obvious. The pertinent section of
for {set i 0} {$i < $num_commands} { incr i} {
send -- "[subst -nocommands [lindex $commands $i]]\r"
expect {
-re "^\[^\n\r]*$reprompt" { exp_continue }
-re "^\[^\n\r *]*$reprompt" {}
-re "\[\n\r]" { exp_continue }
}
}
And the actual prompt is "root> "
try ktrace (or truss or strace) on the process. it could be that the
device is slow, the expect (tcl) is reading one char at a time, the
tty is in a weird mode; as just a few guesses.

it is not uncommon for single chars to be read sometimes. the key is
create matches that dont consume the single chars; cause it to read
more and concatenate the input into complete lines.
Brian Talley
2011-04-10 20:46:20 UTC
Permalink
Post by john heasley
Post by Brian Talley
I'm creating a custom login script for a Crescendo load balancer device.
I
Post by Brian Talley
can log in to the device and get to interactive mode ok using the script,
crescendologin -d -t 30 -c"show running" host
it appears that expect is trying to match on every character with output
...
send: sending "show running\r" to { exp6 }
expect: does "" (spawn_id exp6) match regular expression "^[^\n\r]*root>
"?
Post by Brian Talley
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no
expect: does "s" (spawn_id exp6) match regular expression "^[^\n\r]*root>
"?
Post by Brian Talley
no
"^[^\n\r ]*>>.*root> "? no
"[\n\r]+"? no
expect: timed out
Error: TIMEOUT reached
I feel like I'm missing something obvious. The pertinent section of
for {set i 0} {$i < $num_commands} { incr i} {
send -- "[subst -nocommands [lindex $commands $i]]\r"
expect {
-re "^\[^\n\r]*$reprompt" { exp_continue }
-re "^\[^\n\r *]*$reprompt" {}
-re "\[\n\r]" { exp_continue }
}
}
And the actual prompt is "root> "
try ktrace (or truss or strace) on the process. it could be that the
device is slow, the expect (tcl) is reading one char at a time, the
tty is in a weird mode; as just a few guesses.
it is not uncommon for single chars to be read sometimes. the key is
create matches that dont consume the single chars; cause it to read
more and concatenate the input into complete lines.
After some trial and error I was able to get this to work by using

set send_human {.1 .3 1 .05 2}

Thanks,
Brian

Continue reading on narkive:
Loading...