[Israel.pm] Telnet via Perl

Offer Kaye oferk at oren.co.il
Mon Sep 8 08:23:36 PDT 2003

> Hi,
> I'm tring to use Telnet.pm (3.03) with no luck, i have
> the following program:
> #!/usr/local/bin/perl
> use Net::Telnet;
> $t = Net::Telnet->new (Prompt  => '/.*\> $/', Timeout
> => 10) || die;
> $t->open ("ServerName") || die $!;
> $t->login("aaa", "bbb") || die $!;
> @lines = $t->cmd("who");
> print @lines;
> And it dies with the following message:
>   timed-out waiting for command prompt at ./Telnet.pl
> line 7
> Any idea why?

According to the documentation at:
http://search.cpan.org/dist/Net-Telnet/lib/Net/Telnet.pm :
"The methods login() and cmd() use the prompt setting in the object to
determine when a login or remote command is complete. Those methods will
fail with a time-out if you don't set the prompt correctly."

So it looks like you are not setting your prompt correctly. Check that the
pattern match you gave (/.*\> $/) is correct. One thing I saw- you use '\>',
but there is no need for a backslash before the '>' as it is not a
meta-character. This is probably not a problem, just redundant. As for what
exactly the problem is, compare the regexp to the actual prompt being sent.
The "dump_log()" or "input_log()" methods might be useful here.

Hope this helps,
Offer Kaye

More information about the Perl mailing list