Click here to get back home

timeout problem with Net::Telnet

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
timeout problem with Net::Telnet Mr_Noob 03-11-2008
Posted by Mr_Noob on March 11, 2008, 10:42 am
Please log in for more thread options
Hi all,

Here is my perl script that make a telnet connection with a windows2k3
box :


#!/usr/bin/perl -w
use strict;
use warnings;
use Net::Telnet ();
my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
'/$ $/i');

# telnet credentials
my $username = "administrator";
my $password = "mypass";
my $launcher = "c:\my_bat_files\test\launcher.bat";
my $server = "myserver";

# Open telnet connection to $server
$telnet->open($server);
# telnet login/password
$telnet->login($username, $password);
# launch bat file
print $telnet->cmd($launcher);

But i have the following error :

"timed-out waiting for command prompt at scripts/Sanstat_launcher.pl
line 32"

I guess my "Prompt" isn't set correctly but can't find how to correct
this...
Here is how it looks like if i telnet my server manually :


$ telnet myserver
Trying 192.168.1.6...
Connected to myserver.mydomain.com.
Escape character is '^]'.
Welcome to Microsoft Telnet Service

login: administrator
password:

*===============================================================
Welcome to Microsoft Telnet Server.
*===============================================================
C:\Documents and Settings\Administrator>



thx in advance for helping

Posted by J. Gleixner on March 11, 2008, 11:15 am
Please log in for more thread options
Mr_Noob wrote:
> Hi all,
>
> Here is my perl script that make a telnet connection with a windows2k3
> box :
>
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> use Net::Telnet ();
> my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
> '/$ $/i');

That's saying that you want a prompt that ends with a '$ '.

[...]
> I guess my "Prompt" isn't set correctly but can't find how to correct
> this...

You change the regular expression of the Prompt attribute above.

> Here is how it looks like if i telnet my server manually :
>
>
> $ telnet myserver
> Trying 192.168.1.6...
> Connected to myserver.mydomain.com.
> Escape character is '^]'.
> Welcome to Microsoft Telnet Service
>


> login: administrator
> password:

Your prompt on the remote machine would be the 'login: ', then the
'password: '.

Modify your Prompt to match what you're seeing on the remote machine.

Posted by Mr_Noob on March 11, 2008, 2:14 pm
Please log in for more thread options
wrote:
> Mr_Noob wrote:
> > Hi all,
>
> > Here is my perl script that make a telnet connection with a windows2k3
> > box :
>
> > #!/usr/bin/perl -w
> > use strict;
> > use warnings;
> > use Net::Telnet ();
> > my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
> > '/$ $/i');
>
> That's saying that you want a prompt that ends with a '$ '.
>
> [...]
>
> > I guess my "Prompt" isn't set correctly but can't find how to correct
> > this...
>
> You change the regular expression of the Prompt attribute above.
>
> > Here is how it looks like if i telnet my server manually :
>
> > $ telnet myserver
> > Trying 192.168.1.6...
> > Connected to myserver.mydomain.com.
> > Escape character is '^]'.
> > Welcome to Microsoft Telnet Service
>
> > login: administrator
> > password:
>
> Your prompt on the remote machine would be the 'login: ', then the
> 'password: '.
>
> Modify your Prompt to match what you're seeing on the remote machine.


ok, thx for the advise.
But i tried this :

my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
'/login: $/i');

or
my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
'/password:$/i');


my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>
'/login:|password:$/i');

without any success.....


Posted by Ben Morrow on March 11, 2008, 2:53 pm
Please log in for more thread options

> Mr_Noob wrote:
> >
> > Here is my perl script that make a telnet connection with a windows2k3
> > box :

Have you read the notes in Net::Telnet about Microsoft's telnet server?

> > #!/usr/bin/perl -w
> > use strict;
> > use warnings;
> > use Net::Telnet ();
> > my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt =>

Using 'indirect object syntax' (new Net::Telnet (...)) is a bad idea.
Perl's parsing of it is somewhat flakey, and it's better to use normal
object syntax:

my $telnet = Net::Telnet->new(...);

> > '/$ $/i');
>
> That's saying that you want a prompt that ends with a '$ '.
<snip>
>
> Your prompt on the remote machine would be the 'login: ', then the
> 'password: '.

No, it wouldn't. Net::Telnet handles the login prompts itself. The
prompt on a Win32 machine is something like qr/\>$/ or qr/\> $/: whatever
the shell prints just before you enter a command.

Ben


Posted by szr on March 12, 2008, 12:11 am
Please log in for more thread options
Ben Morrow wrote:
>> Mr_Noob wrote:
>>>
>>> Here is my perl script that make a telnet connection with a
>>> windows2k3 box :
>
> Have you read the notes in Net::Telnet about Microsoft's telnet
> server?
>
>>> #!/usr/bin/perl -w
>>> use strict;
>>> use warnings;
>>> use Net::Telnet ();
>>> my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt
>>> =>
>
> Using 'indirect object syntax' (new Net::Telnet (...)) is a bad idea.
> Perl's parsing of it is somewhat flakey, and it's better to use normal
> object syntax:
>
> my $telnet = Net::Telnet->new(...);

I have never had an issue using the indirect syntax. I find it more
comfortable, having a c++/java background before I learned Perl some
time ago. Exactly what difference does it make, if any (as I have never
found any) ?

--
szr



Similar ThreadsPosted
timeout problem February 13, 2007, 8:16 am
Perl script timeout problem February 17, 2005, 10:53 am
Net::Telnet prompt problem April 13, 2005, 1:22 pm
Problem closing app that was launched via Telnet January 5, 2006, 6:04 am
How do I set timeout in Net::HTTP? January 25, 2006, 7:43 pm
How do I set timeout in Net::HTTP? January 25, 2006, 7:43 pm
How do I set timeout in Net::HTTP? January 25, 2006, 7:43 pm
How do I set timeout in Net::HTTP? January 25, 2006, 7:43 pm
Timeout value in Net::FTP seems to have no effect March 16, 2006, 4:19 am
perl ssh with timeout? March 19, 2006, 11:50 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap