I'm trying to work with Cisco hardware.
Simple script read the config:
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Net::Telnet;
- my $t;
- my $host = "megahw";
- my $username = "megauser";
- my $passwd = "megapassword";
- my @lines = ();
- my $fh;
- my $fn = "/var/tmp/t.log";
- my $lline;
- my @llines = ();
- my $ownline;
- my $screenlines;
- $t = new Net::Telnet(Timeout => 10, Prompt => '/Username: $/');
- $t->open($host);
- $fh = $t->input_log($fn);
- $t->login(Name => $username, Password => $passwd, Prompt => '/#$/');
- $t->print("show running-config");
- @lines = ();
- $ownline = 1;
- $screenlines = 25;
- while (1){
- @llines = $t->getlines(All => 0);
- $lline = scalar @llines;
- if ($lline == $screenlines){
- while (scalar @llines){
- $lline = shift @llines;
- push @lines, $lline;
- }
- if ($ownline){
- $ownline = 0;
- $screenlines -= 2;
- }
- $t->put(' ');
- next;
- }else{
- while (scalar @llines){
- $lline = shift @llines;
- push @lines, $lline;
- }
- last;
- }
- }
- $t->print("exit");
- $t->break;
- $t->close;
- while (scalar @lines){
- $lline = shift @lines;
- print $lline;
- }
Expand|Select|Wrap|Line Numbers
- User Access Verification
- Username: megauser
- Password:
- megahw#show running-config
If I run it via perl -d script.pl and go inside while(1) loop via n(ext) commands and then c(continue), the t.log has:
Expand|Select|Wrap|Line Numbers
- User Access Verification
- Username: megauser
- Password:
- megahw#show running-config
- Building configuration...
- Current configuration : 2201 bytes
- !
- ! No configuration change since last restart
- !
- version 15.2
- no service pad
- service timestamps debug datetime msec
- service timestamps log datetime msec
- !
- hostname megahw
- !
- boot-start-marker
- !
- There are many lines of config
- !
- end
Any clues?