tags:

views:

27

answers:

2

Hello, everyone

I'm trying to automate the interaction with a remote device over telnet using expect. At some point device generates output like this:

;
...
COMPLETED
...
;

What I need is to make my script exit after the "COMPLETED" keyword and second ";" are found. However all my attemts fail. Script either exits after the first coma or does not exit at all, hanging. Please help.

+1  A: 

How about: expect -re {COMPLETED.+;}

glenn jackman
That didn't work :-(
facha
add `exp_internal 1` to your script -- you will see what expect sees and find out why your patterns don't match.
glenn jackman
ok. I've got it working. There was another COMPLETED...; block way before the one I've been trying to react on. Thanks a lot to everyone for your help.
facha
+1  A: 

Expect works.

I make a point of that, because facha has already written "That [presumably the updated script, rather than Expect itself] didn't work" once. Expect has very few faults--but it's so unfamiliar to most programmers and administrators that it can be hard to discern exactly how to talk to it. Glenn's advice to

expect -re {COMPLETE.+;}

and

exp_internal 1

(or -d on the command line, or so on) is perfectly on-target: from everything I know, those are exactly the first two steps to take in this situation.

I'll speculate a bit: from the evidence provided so far, I wonder whether the expect matches truly even get to the COMPLETE segment. Also, be aware that, if the device to which one is telnetting is sufficiently squirrelly, even something as innocent-looking as "COMPLETE" might actually embed control characters. Your only hopes in such cases are to resort to debugging techniques like exp_internal, or autoexpect.

Cameron Laird