telnet in perl

  • shoeb83
  • Born
  • Born
  • shoeb83
  • Posts: 2

Post 3+ Months Ago

I want to telnet from a unix platform to a remote server and execute some commands (like ls -l).

It is need to automate the process. Searching google I found Net::Telnet but did not understand actually what to do.

I'll be glad if anybody help me in this regards.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

First of all, if it's not your server, chances are that sshd is running & not telnetd.

In either case, you need a user name & password on the server. Do you have that?

Here's an example. From my Unix box I connected to my Linux box.

queyosepa# ssh -l don 192.168.1.21
donoli@192.168.1.21's password:
Linux don-desktop 2.6.24-26-386 #1 Tue Dec 1 17:56:13 UTC 2009 i686
Last login: Mon Feb 8 20:34:26 2010 from 192.168.1.97
don@don-desktop:~$ls -asl
4 drwxr-xr-x 36 don don 4096 2010-02-08 20:30 .
4 drwxr-xr-x 3 root root 4096 2008-08-23 23:31 ..
8 -rw------- 1 don don 6027 2010-02-06 19:44 .bash_history
4 -rw-r--r-- 1 don don 220 2008-08-23 23:31 .bash_logout
4 -rw-r--r-- 1 don don 414 2008-08-23 23:31 .bash_profile
etc....snipped to save space.
  • shoeb83
  • Born
  • Born
  • shoeb83
  • Posts: 2

Post 3+ Months Ago

I think a cannot make you understand the problem.

I can telnet to a server from the terminal like below

telnet 192.168.111.111

login: testuser
Password:
Last login: Tue ..........................
........................................

Then I can execute commands like below
ls -l
...
...


I want to do this task using a perl script to do it automatically.
  • Don2007
  • Web Master
  • Web Master
  • Don2007
  • Posts: 4924
  • Loc: NY

Post 3+ Months Ago

Sorry, I don't know perl. Maybe someone else can help you.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Net::Telnet is pretty straightforward:
Code: [ Select ]
#!/usr/bin/perl
use Net::Telnet;
$conn = new Net::Telnet(Timeout=>30,Errmode=>'die' Prompt => '/\$ $/i');
$conn->open('my.domain.com');
$conn->login('username','password');
@output = $conn->cmd('ls -l');
$conn->close;
  1. #!/usr/bin/perl
  2. use Net::Telnet;
  3. $conn = new Net::Telnet(Timeout=>30,Errmode=>'die' Prompt => '/\$ $/i');
  4. $conn->open('my.domain.com');
  5. $conn->login('username','password');
  6. @output = $conn->cmd('ls -l');
  7. $conn->close;


Take a look here for more info:
http://search.cpan.org/~jrogers/Net-Tel ... /Telnet.pm

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 127 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.