All,

I'm new to using Perl's Expect module so maybe I'm going about this the wrong way. Basically, with the code below i'm trying to login, run a script and exit. But, because the 1st thing that is returned from a telnet is "Trying aaa.bb.ccc.ddd ... " and my script gets stuck in a endless loop. Any pointers ?

use strict; use warnings; use Expect; $Expect::Exp_Internal = 1; my $my_login = "xxx"; my $my_password = "yyy"; my $timeout = "5"; #Spawn a Telnet Process to connect to a build machine. my $exp = Expect->spawn("telnet aaa.bb.ccc.ddd") or die "Cannot Spawn Telnet...exiting\n"; #Send user name a password. $exp->expect($timeout, [ qr/^login:\s+$/i, sub { my $self = shift; $self->send("$my_login\n"); exp_continue; } ], [ qr/^password:\s+$/i, sub { my $self = shift; $self->send("$my_password\n"); exp_continue; } ], # [ qr/.*/i, sub { my $self = shift; # $self->send("/sean/test.pl\n"); # i exp_continue; } ], [ qr/^COMPLETE.*$/i, sub { my $self = shift; $self->send("exit\n"); exit; } ], [ qr/.*/i, sub { my $self = shift; exp_continue; } ], );

In reply to Need some pointers using Expect.pm by TASdvlper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.