I wrote a simple script to interface with some Cisco routers on our network (3745's mainly) and have run into some issues using Net::Telnet's function "waitfor"

#!/usr/bin/perl -w use strict; use Net::Telnet; die "Required argument missing!\n" unless ($ARGV[0]); my $target = $ARGV[0]; my $password = "password"; my $telnet = new Net::Telnet (Timeout => 60, Errmode => 'die', Telnetmode => '1', Input_log => "$target.txt", Dump_log => "dump_log.txt"); $telnet->open(Host => $target, Port => '23') || die "Cannot open telnet connection to $ +target"; $telnet->print($password) if ($telnet->waitfor('/Password:/')); $telnet->print('ena') if ($telnet->waitfor('/\>/')); $telnet->print($password) if ($telnet->waitfor('/Password:/')); $telnet->print('sh run') if ($telnet->waitfor('/#/')); while (1) { if ($telnet->waitfor('/--More--/')) { $telnet->print(chr(32)); }else{ print "Configuration file for $target has been successfully save +d!\n"; exit(0) } }
Now as you can see inside the while loop I look for the prompt of "--More--" which is what all cisco gear returns when the listed query is longer than will fit on one page. I have this working properly and it loops through the entire "sh run" command but never exits because it keeps waiting for "--More--".

The nature of the "waitfor()" command will wait as long as you have set the "timeout" argument for for the desired prompt. This works fine as long as the program recieves this prompt. However after the entire configuration for the router has been listed it goes back to the router shell prompt.

This input recieved from the router does not match the target text in the waitfor() function so the script waits like it is suppose to. I need a way to do what I have tried here, to exit if the waitfor() does not recieve the desired text (meaning the entire con fig has been listed).

Any ideas?

Oh and I have looked into using the Net::Telnet::Cisco module too but it appears that this module would give me a similar problem.


In reply to Net::Telnet issues! by Elijah

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.