Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Problem with Net::Telnet

by frozenwithjoy (Curate)
on Nov 25, 2012 at 23:03 UTC ( #1005535=note: print w/ replies, xml ) Need Help??


in reply to Problem with Net::Telnet

There may be other problems, but the use of single quotes prevents $device from being interpolated in:

$telnet->waitfor('/$device"."# /i'); ##wait for prompt
Does using the following instead help get rid of errors?
$telnet->waitfor( qq{/$device"."# /i} ); ##wait for prompt


Comment on Re: Problem with Net::Telnet
Select or Download Code
Re^2: Problem with Net::Telnet
by SDN (Initiate) on Nov 26, 2012 at 00:34 UTC
    That definitely helped. At least I know it was a syntax issue. Now my only problem is I'm getting a 'pattern match timed-out' error.
    Uncaught exception from user code: pattern match timed-out at scopedzT1 line 279 at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm line 2036 Net::Telnet::_croak('Net::Telnet=GLOB(0x3a684c)', 'pattern mat +ch timed-out') called at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm +line 539 Net::Telnet::error('Net::Telnet=GLOB(0x3a684c)', 'pattern matc +h timed-out') called at /sw/lib/perl5/site_perl/5.8.8/Net/Telnet.pm l +ine 1995 Net::Telnet::waitfor('Net::Telnet=GLOB(0x3a684c)', '/yyyy# /i' +) called at scopedzT1 line 279

    I'm guessing it's just a pattern match issue with the prompt. I'm actually getting into the device. At least that is what the output file is showing me. Is there any way around the pattern match error? The output file is actually showing the correct prompt. Unsure why it's failing. Thanks for your help.
      Can you determine at which pattern match it is timing out based on the line # or printing debug statements to STDOUT between telnet calls?
        Yes, it's right at line 24 where it times out.
        $telnet->waitfor('/$device# /i'); ##wait for prompt
        From the output I can see it authenticate, but once I get to the prompt it times out. My output file looks something like this:
        username: xxxx
        password: zzzz
        yyyy#

        Now if I remove $device and just enter a specific name followed by the prompt(#), it prints out exactly what I want. It's just when I try to use a variable I run into this problem.
        $telnet->waitfor('/yyyy# /i'); ##wait for prompt

        This works. Maybe it has something to do with the prompt? I removed "." from the line and it still times out.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005535]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-07-13 07:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (248 votes), past polls