timeout problem with Net::Telnet

M

Mr_Noob

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
 
J

J. Gleixner

Mr_Noob said:
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.
 
M

Mr_Noob

Mr_Noob said:
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.....
 
B

Ben Morrow

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

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(...);
That's saying that you want a prompt that ends with a '$ '.
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
 
S

szr

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


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) ?
 
T

Tad J McClellan

szr said:
Ben Morrow wrote:
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) ?


See the "Indirect Object Syntax" section in perlobj.pod.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top