?
Solved

Telent in Perl with no Prompt

Posted on 2009-07-14
5
Medium Priority
?
523 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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
$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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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
Suggested Courses

801 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