LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Using Perl NET::TELNET module (https://www.linuxquestions.org/questions/linux-networking-3/using-perl-net-telnet-module-290235/)

DannyM 02-14-2005 04:50 PM

Using Perl NET::TELNET module
 
I am just starting to look at the NET:TELNET module available in perl. I am new to both linux and perl. I have managed to get the modules installed but am having problems getting the output back from commands that i issue. My script file is :

#!/usr/bin/perl

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'die'
Prompt=>'/\$ $/i');
$telnet->open('192.168.1.4');
$telnet->login('danny', 'danny');
print $telnet->cmd('ls');


When testing this on my local suse box i get the error :

linux:/home/test-stuff # ./test.pl
syntax error at ./test.pl line 8, near "Prompt"
Execution of ./test.pl aborted due to compilation errors.
linux:/home/test-stuff #

What am i doing wrong ?

Ultimatley my aim is to use NET::TELNET::CISCO module to automate commands to cisco routers. I though id better get the above working first as im new to it !

Any help appreciated

Thanks

sigsegv 02-14-2005 05:19 PM

Should read:

Code:

$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt=>'/\$ $/i');
You're missing a comma

DannyM 02-14-2005 05:31 PM

Thanks, it now seems to let me login however the 'ls' command is not being run. The output i am seeing is :

linux:/home/test-stuff # ./test.pl
eof read waiting for login prompt: Welcome to SuSE Linux 9.2 (i586) - Kernel 2.6.8-24.11-default (3). at ./test.pl line 6
linux:/home/test-stuff #


my current script is :

#!/usr/bin/perl

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>20, Errmode=>'die', Prompt=>'/\$ $/i');
$telnet->open('192.168.1.3');
$telnet->login('root', 'password');
print $telnet->cmd('ls');

Any suggestions ?

Thanks

sigsegv 02-14-2005 08:33 PM

Try adding some error checking. Something like:

Code:

$telnet->login('root', 'password') or die("Problem logging in: $!");
Note: I don't know if this will actually work or not as I don't have anything running telnet to check it with and I'm not familiar with the Net::Telnet module, but it should.

zymurgist 02-15-2005 11:31 AM

Full path to ls may help. Probably /bin/ls.


All times are GMT -5. The time now is 11:40 AM.