Telent in Perl with no Prompt

Posted on 2009-07-14
Medium Priority
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.
Question by:johnnygon
  • 3
  • 2
LVL 39

Expert Comment

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.

Author Comment

ID: 24854372
Do you have an example?  I just get nothing back.
LVL 39

Accepted Solution

Adam314 earned 2000 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
##### 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
##### Do you need to wait for something, or wait a certain amount of time?
my $output = $telnet->get(Timeout => 10);

Open in new window


Author Comment

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.
LVL 39

Expert Comment

ID: 24856467

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

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
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…
Six Sigma Control Plans

600 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