I have a long script that is getting stuck while handling the > (enable) mode.
I am trying to authenticate in the following two senarios-

1)
username:
password:
Device>

1st scenario- getting stuck at Device>.

2)
Device>
Same for the 2nd scenario stuck at Device>.

use warnings; use Net::Telnet; my $Telnet = new Net::Telnet; my $InHandle = $Telnet->input_log("input.txt"); my $OutHandle = $Telnet->output_log("output.txt"); my $prmpt = '/[\w().-]*[\$#>:.]\s?(?:\(>\))?\s*$/'; $host="172.16.1.1"; $username = "user"; $password = "pass"; $enpwd = "enable"; my $telnet = Net::Telnet->new( Host => $host, Input_log => "input.log", Output_log => "output.log", Dump_Log => "dump.log", Timeout => 10); # provide host address $telnet->open("$host"); print "\n\n Connecting to $host\n"; # authentication @out = $telnet->waitfor('/Username: $/i') || next; $telnet->print($username); print "@out\n"; # for tshoot only @out = $telnet->waitfor('/Password: $/i') || next; $telnet->print($password); print "@out\n"; # for tshoot only # if enable, send "enable" and enable-pwd unless ($telnet->waitfor('/Username: $/i' | '/#/i')) { #$telnet->waitfor('/>/'); @out = $telnet->print('enable'); print "@out\n"; # for tshoot only @out = $telnet->print($enpwd); print "@out\n"; # for tshoot only } print "username, password, & enable mode authentication accepted-\n"; $telnet->close;
Output:
Connecting to 172.16.1.1 1 1 pattern match timed-out at c:\temp\dirB2D.tmp\testing 3.pl line 35 Press any key to continue . . . Connecting to 172.16.1.2 pattern match timed-out at c:\temp\dirEDA1.tmp\testing 3.pl line 26 Press any key to continue . . .
I get the username and password passes thru in Scenario 1 but gets stuck in enable. Scenario 2 with .1.2 it doesn't like @out = $telnet->waitfor('/Username: $/i').
Please help!

Updated: code

In reply to Cannot get enable> mode to work by ArifS

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.