Solved

Telent in Perl with no Prompt

Posted on 2009-07-14
5
483 Views
Last Modified: 2012-05-07
I need to open a telnet session in perl and capture the output to a file.  The device has no prompt basically I telnet in send the command STS and it returns a string.
Does anyone have a script for this, everything I have found here doesnt work.
0
Comment
Question by:johnnygon
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:Adam314
Comment Utility
You can use Net::Telnet, just don't use the cmd or login methods.  You can still send data, and receive data though.
0
 
LVL 1

Author Comment

by:johnnygon
Comment Utility
Do you have an example?  I just get nothing back.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
Comment Utility
Do you send newline characters after the commands?  If not, you need to change the output record separator.  Otherwise, this should work.
use Net::Telnet;
 

my $telnet = Net::Telnet->new(

  Dump_Log   => 'dump.log',

  Input_log  => 'input.log',

  Output_log => 'output.log',

  Host       => 'your-hostname-here',

  );
 

##### Send username/password, if needed

$telnet->print("username");

$telnet->print("password");
 

##### If there is anything that lets you know you logged in successfully, look for it

$telnet->waitfor('/You are logged in/');
 

##### Send whatever else is needed

$telnet->print('STS');
 

##### Do you need to wait for something, or wait a certain amount of time?

my $output = $telnet->get(Timeout => 10);

Open in new window

0
 
LVL 1

Author Comment

by:johnnygon
Comment Utility
What if I want to send another print based on the response I get from the get? It doesnt seem to want to loop.
0
 
LVL 39

Expert Comment

by:Adam314
Comment Utility

...

if($output =~ /my expected output/) {

    $telnet->print('some new command');

}

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now