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

Ok this may sound like a stuipd question to you guys, but I am a newbie. I am using net::telnet module to get running configurations off of some of our devices. One of the devices kicks a --More-- prompt. I have the script to auto page this. However it is returning to the show run, I can not figure out why. It may be that I have been looking at it too long. Can you please help? Thank you gratefully!!
my ($bwlogin,$bwpass,$bwenable) = split (/,/,$pass{$type}); $telnet->print($bwlogin); $telnet->waitfor('/Password: $/i'); $telnet->print($bwpass); my ($pre,$match) = $telnet->waitfor(Match => '/>$/i', Match => '/Login incorrect/'); $match =~ />/ or return warn "Logon failed for $host \n"; $telnet->print("enable"); $telnet->waitfor('/Password:$/i'); $telnet->print($bwenable); ($pre,$match) = $telnet->waitfor(Match => '/#$/i', Match => '/\% authentication faile +d/'); $match =~ /#/ or return warn "Enable failed for $host \n"; while ($telnet->print("show run")){ ($pre,$match) = $telnet->waitfor(Match => '/\-\-More\-\-$/i', Match => '/#$/i'); if ($match =~ /\-\-More\-\-/){ $telnet->print(" "); } if ($match =~ /#/){ $telnet->print("exit"); } } }

Replies are listed 'Best First'.
Re: Net::Telnet while loop not exiting (Newbie Please be Gentle)
by shenme (Priest) on Sep 20, 2003 at 06:53 UTC
    Any chance this is simply timing out?   Apparently the default timeout for some/most operations including waitfor() is set at new() time and defaults to 10 seconds. (You can change it with timeout()

    If we take the Net::Telnet internals as canon,

    ## Wait for login prompt. $self->waitfor(-match => '/login[: ]*$/i', -match => '/username[: ]*$/i') or do { return &$error("read eof waiting for login prompt") if $self->eof; return &$error("timed-out waiting for login prompt"); };
    then maybe you should also test for the eof and timeout conditions.

    Obligatory nit: I don't think you need to escape the '-' characters if they aren't inside a character class, e.g. /--[!?]--/ )

Re: Net::Telnet while loop not exiting (Newbie Please be Gentle)
by blackstealth (Novice) on Sep 20, 2003 at 06:55 UTC
    Well I knew I had been looking at it a long time. I figured it out for myself. Thanks for all your help though. I had to remove the double if and take the exit out of the loop.
      could you please share your script, I am working on a script like that, and I don't find the solution thanks