[Trilug-ontopic] YAEQ (yet another Expect question)

Greg Brown gwbrown1 at gmail.com
Wed Jan 20 15:02:25 EST 2010

I'm getting closer.. the Expect.pm module does support regular expressions
in the from of placing a '-re',"what I'm trying to match*"); but $match
still only has the portion of what is matched up to the "*"; the rest seems
tossed by the regular expression match.  I also can't seem to find the magic
variable that contains the full previous line returned.. if I can find that
I can use it but it doesn't appear to be anywhere that I can locate (i.e. $_
or @_ which was, I admit, just a wild guess).

On Wed, Jan 20, 2010 at 2:35 PM, Greg Brown <gwbrown1 at gmail.com> wrote:

> First and foremost, I need to get this script finished and I don't have
> time to learn Python but it's on the to-do list.
> Ok, that said I'm ssh'ing to a remote server (an IDS sensor, really) and
> I'm trying to read back prompts.  Trouble is when you run a setup command
> the prompt is going to change each time.  Here's an example of what I'm
> dealing with:
> #!/usr/bin/perl
> use Expect;
> $ssh = Expect->spawn("ssh -l greg myserver");
> # wait for the prompt
> my($which, $why, $match, $before, $after) = $ssh->expect(30,"assword:)";
> # send the password
> print $ssh "myPassword\r";
> # now here's where we run into problems, the prompt is going to change
> dynamically and there is no way I can change that
> my($which, $why, $match, $before, $after) = $ssh->expect(30,":");
> And there is where I run into problems.. the prompt for each system I ssh
> to will change dynamically and I want to capture the entire prompt but the
> $match variable only catches what it matches, not the entire line so $match
> would equal ":" not "gregtest(" and I want to be able to
> capture that IP address.
> What I can't seem to get working is a way to put a regular expression
> inside what I want to match, i.e. I can't seem to say:
> my($which, $why, $match, $before, $after) = $ssh->expect(30,"greg*:");
> That doesn't work.
> Any ideas?  I'd really like to get this working.
> Back to google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.trilug.org/pipermail/trilug-ontopic/attachments/20100120/b8d32fa7/attachment.htm>

More information about the Trilug-ontopic mailing list