Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

using NET::TELNET waiting for login prompt

by Altiokis (Initiate)
on Aug 15, 2012 at 23:15 UTC ( [id://987652]=perlquestion: print w/replies, xml ) Need Help??

Altiokis has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on the beginings of a portion of some perl code that is to telnet into a node using telnet. This snippet of code works fine telnetting into a linux box, but doesn't work logging into my node. Here is what my code looks like.
use strict; use Net::Telnet (); my $t = new Net::Telnet Timeout => 30, Prompt => '/[\$#%:><] $/'; $t->open($ARGV[0]); $t->login($ARGV[1], $ARGV[2]); my @lines = $t->cmd("MY CMD/;"); print @lines;
and this is what the login looks like. I'm thinking it's all the white space between the Escape character message and the actual login prompt, but i don't know how to account for that.
Trying 1.1.1.1... Connected to 1.1.1.1. Escape character is '^]'. ENTER USERNAME < ENTER PASSWORD <

Replies are listed 'Best First'.
Re: using NET::TELNET waiting for login prompt
by Illuminatus (Curate) on Aug 15, 2012 at 23:34 UTC
    Did you look at the documentation for Net::Telnet? It gives you several things to try (like using dump_log() or input_log()). If you did use those, what did they tell you? Are you sure that there's just a single space after the < in the prompt? Your regexp will only match a single space and the EOL. If there are no spaces or more than one, it won't match

    fnord

      Here's what the input.log shows
      ENTER USERNAME < ^H
        Assuming the ^H at the end is part of the data received by your program, then that's what's causing the failure. You could try
        ... Prompt => '/[\$#%:><][\s\b]+$/ ...
        If that doesn't work, the output from dump_log() might also be helpful.

        fnord

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://987652]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found