getlines from Net::Telnet works different (works/does not work). while loop opt?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • p1qb0d
    New Member
    • May 2016
    • 2

    getlines from Net::Telnet works different (works/does not work). while loop opt?

    Hello.

    I'm trying to work with Cisco hardware.

    Simple script read the config:
    Code:
    #!/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;
    }
    If I run it flat (script.pl) I get my own command only. t.log has:
    Code:
    
    User Access Verification
    
    Username: megauser
    Password: 
    
    megahw#show running-config
    If I run it via perl -d script.pl and type c(ontinue) immediately the t.log is the same.

    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:
    Code:
    
    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
    That behaviour is very strange for me.

    Any clues?
Working...