Solved

Telent in Perl with no Prompt

Posted on 2009-07-14
5
508 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
ID: 24854269
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
ID: 24854372
Do you have an example?  I just get nothing back.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 24854448
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
ID: 24855782
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
ID: 24856467

...
if($output =~ /my expected output/) {
    $telnet->print('some new command');
}

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

821 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