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

Hi I have been trapped in a problem and I hope that you guys will help me. The problem is while telnet to router and I submit a show command and the router gives the first page of output and present "CR to continue--" and stop showing the rest of the output and wait for carriage return. Now the question is how can I interactively enter carriage return "\r". here is the piece of code $telnet->print('sh ip route'); print $telnet->waitfor('/.+CR to continue--/i' or '/.?+#/i') or die $telnet->errmsg; It worked for the command output that ask CR once and not worked better for the commands output that are bigger. Any help would be appreciable. Thanks !

Replies are listed 'Best First'.
Re: telnet to router
by almut (Canon) on Mar 08, 2010 at 23:04 UTC
    Now the question is how can I interactively enter carriage return "\r".

    Not quite sure whether you want the paging to continue by literally entering CR on the terminal from which you ran the script (i.e. by interactively pressing ^M), or whether you want the script to automatically send CR.  In case of the latter, have you tried put() after the waitfor()?

    $telnet->put("\r");
Re: telnet to router
by chuckbutler (Monsignor) on Mar 09, 2010 at 00:45 UTC

    There is a CPAN Module Net::Telnet::Cisco that works very well under most cases. The module handles the paging. Also, as long as the device behaves like Cisco CLI you should be OK.

    Normally, on current Cisco devices, the prompt waiting on a paging is '--More--', and responding with a CR, "\r", returns only the next line of output, but responding with a Space, " ", returns the next page or the remaining text.

    Good luck. -c

Re: telnet to router
by ssandv (Hermit) on Mar 08, 2010 at 23:39 UTC

    Please read the formatting directions at the bottom of the posting box--especially the one about putting <code></code>tags around your code.

    Algorithmically, what you probably need to do is waitfor either the "CR to continue" string or the prompt, and loop back as long as you keep getting the former.

Re: telnet to router
by VinsWorldcom (Prior) on Mar 09, 2010 at 14:09 UTC

    As told in previous posts - Net::Telnet::Cisco - is the way to go (judging by your "show ip route" command I'm guessing your on a Cisco device). The Net::Telnet::Cisco module has an autopaging feature; however, I've never gotten it to work.

    The *solution* is that after connecting, the first command you issue should be "terminal length 0". This effectively turns off paging in the router and eliminates the need for the -More- prompt catching and RETURN pressing.