Elijah has asked for the wisdom of the Perl Monks concerning the following question:
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--".#!/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) } }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Telnet issues!
by NetWallah (Canon) on Mar 20, 2004 at 00:43 UTC | |
by hsinclai (Deacon) on Mar 20, 2004 at 02:02 UTC | |
|
Re: Net::Telnet issues!
by Anonymous Monk on Mar 20, 2004 at 02:47 UTC | |
|
Re: Net::Telnet issues!
by eXile (Priest) on Mar 20, 2004 at 01:14 UTC | |
|
Re: Net::Telnet issues!
by Anonymous Monk on Mar 20, 2004 at 23:51 UTC |