views:

233

answers:

2

I'm written small code to connect to remote server using Perl but observing error messages

#!/usr/bin/perl -w

use Net::Telnet;

$telnet = new Net::Telnet ( Timeout=>60, Errmode=>'die');

$telnet->open('192.168.50.40');

$telnet->waitfor('/login:/');

$telnet->print('queen');

$telnet->waitfor('/password:/');

$telnet->print('kinG!');

$telnet->waitfor('/:/');

$telnet->print('vol >> C:\result.txt');

$telnet->waitfor('/:/');

$telnet->cmd("mkdir vol");

$telnet->print('mkdir vol234');

$telnet->cmd("mkdir vol1");

$telnet->waitfor('/\$ $/i'); 

$telnet->print('whoamI');

print $output;

But while running i'm getting following errors

C:\>perl -c E:\test\net.pl

E:\test\net.pl syntax OK

C:\>perl E:\test\net.pl

command timed-out at E:\test\net.pl line 13

C:\>

Help me in this regard. I'm new to Perl.

+1  A: 

I'm not sure about that Net::Telnet, but using '/:/' (with quotes) I guess is the problem. I.e. /:/ (within slashes) - that's regular expression, but with quotes that's simply string which should appear on terminal (i.e. it waits for string '/:/' - slash, two dots, slash).

To debug such programs (if Net::Telnet doesn't echo interaction with remote system) you can simply put: print "I'm waiting for login...\n" at lines before waitfor()

ony
A: 

Why aren't you using Net::Telnet's login method to log-in? When you're at such a low level, you have to handle all of the details yourself. If you look in the source for that method, you'll see it doing quite a bit of work, including a kludge to get around a login bug on Linux.

brian d foy