LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2005, 04:50 PM   #1
DannyM
LQ Newbie
 
Registered: Feb 2005
Posts: 2

Rep: Reputation: 0
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
 
Old 02-14-2005, 05:19 PM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
Should read:

Code:
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt=>'/\$ $/i');
You're missing a comma
 
Old 02-14-2005, 05:31 PM   #3
DannyM
LQ Newbie
 
Registered: Feb 2005
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 02-14-2005, 08:33 PM   #4
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
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.
 
Old 02-15-2005, 11:31 AM   #5
zymurgist
Member
 
Registered: Jan 2003
Location: Long Island
Distribution: Redhat 8.0
Posts: 109

Rep: Reputation: 15
Full path to ls may help. Probably /bin/ls.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i install net-Telnet Whiteghost Linux - General 1 10-10-2005 10:27 AM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
Net::Telnet question on perl. mosh Programming 3 08-10-2004 09:43 AM
Net::Telnet mrPhantastik Programming 5 09-10-2003 02:58 PM
perl-module Net::RawIP - install problem nic_d Linux - Software 0 07-06-2002 07:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration