Home > Archive > PERL Modules > April 2007 > Net::Telnet $prematch, $match
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Net::Telnet $prematch, $match
|
|
| ton de w 2007-04-12, 6:58 pm |
| Hello,
I am looking at a code fragment that I dont understand properly.
...
my ($prematch, $match) = $telnet->waitfor('/login: $i);
$telnet->print($user);
if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
password'))
{
crash out - cannot go on
}
my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
my($prematch, $match) = $telnet->print($password);
....
So what I do understand is line1 we wait for "login: " case
insensitive.
Then line2 supply the user - ($prematch, $match) not used at this
point.
line 3 - i am not really sure - $prematch contains the match up to
expression and $match the match expression but what is the if
statement comparing?
And how if we dont get the 'Choose new password' do we continue to
provide the password?
Actually I need to extend this program to do very similar things - is
there an alternative way of doing this?
TIA
Ton
| |
| Jim Gibson 2007-04-12, 6:58 pm |
| In article <1176387487.128680.166810@b75g2000hsg.googlegroups.com>, ton
de w <ton_de_winter@yahoo.co.uk> wrote:
> Hello,
> I am looking at a code fragment that I dont understand properly.
> ..
> my ($prematch, $match) = $telnet->waitfor('/login: $i);
I think you need '/login: $/i' there.
> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }
> my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
> my($prematch, $match) = $telnet->print($password);
> ...
>
> So what I do understand is line1 we wait for "login: " case
> insensitive.
> Then line2 supply the user - ($prematch, $match) not used at this
> point.
> line 3 - i am not really sure - $prematch contains the match up to
> expression and $match the match expression but what is the if
> statement comparing?
> And how if we dont get the 'Choose new password' do we continue to
> provide the password?
My guess: check for a Timeout parameter in the call to new(). Also
check for a Errmode parameter or a call to errmode. My guess is that
your call to waitfor(string=>'Choose ...') is timing out and proceeding
to the next call (waitfor('/password: $/i');)
Note: it helps if you post a complete, minimal program so we don't have
to guess at what is going on.
>
> Actually I need to extend this program to do very similar things - is
> there an alternative way of doing this?
There is the Expect program:
<http://en.wikipedia.org/wiki/Expect>
<http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod>
or the Perl Expect.pm module:
<http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod>.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
| |
| Mumia W. 2007-04-12, 6:58 pm |
| On 04/12/2007 09:18 AM, ton de w wrote:
> Hello,
> I am looking at a code fragment that I dont understand properly.
> ...
> my ($prematch, $match) = $telnet->waitfor('/login: $i);
> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }
I'm assuming that the "errmode" is "return." When the second
$telnet->waitfor() succeeds, the method will return a list containing
values for $prematch and $match. If that happens, it means that the host
is demanding a new password, and since the script can't handle that, it
exits. The "if" statement tests whether a non-empty list was returned by
$telnet->waitfor().
> [...]
|
|
|
|
|