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

I wrote a script that logs into a router and issues a 'show log' command. The entire show log is not captured and I believe it is do to a buffer issue. I have increased the max_buffer_length as high as possible - no luck. I manually set the bufmaxsize in Telnet.pm to over 8mb and still no luck. Anybody have some suggestions?

Thanks in Advanced!

Here is a scaled down snippet. The '@output = $session->cmd("show log");' is the command I need the full content of the routers show log. Yet the output array only extracts about 1/2 the log:

#!/usr/bin/perl

$username = "cisco";
$password = "cisco";
$enable_password = "cisco";
$zero_screen = "term len 0";

sub scan_log {
  my $cmd = "show log";
  my @output;
  my $previous;
 
  @output = $session->cmd("$cmd");
 
  foreach my $line (@output) {
    chomp($line);
    if ($line =~ /Trace/) {
      print "TRACEBACK MSG: $previous\n";
      print "TRACEBACK: $line\n";
    } else {
      $previous = $line;
    }
  }
}
 
sub node_login {
  my ($node_log) = @_;
  my $buffer_mb = 1024 * 1024;
 
  print "Logging into node: $node ...\n";
 
  # Login to node
  $session = Net::Telnet::Cisco->new(Host        => $node,
                                     Timeout     => $node_timeout,
                                     Prompt      => $prompt);
                                     #Dump_Log    => "dump.log",
                                     #Output_Log  => "commands_run.log",
                                     #Input_log   => $node_log);
 
  $session->send_wakeup;
  $session->login("$username", "$password");
  $session->enable($enable_password);
  $session->max_buffer_length(5 * $buffer_mb);
  $session->cmd($zero_screen);
}
 
$node = "router1"; 

node_login($node_log);
scan_log();

exit;
  • Comment on perl Telnet.pm and Cisco.pm input buffer

Replies are listed 'Best First'.
Re: perl Telnet.pm and Cisco.pm input buffer
by NetWallah (Canon) on Oct 30, 2009 at 03:56 UTC
    You probably need to send the cisco something like
    set cli pagination off
    or
    ter­minal length 0
    In order to get more than 1 "page" worth at a time.

    Either that, or keep sending CR, to get the next page of data, until there is no more.

    Also, please see Writeup Formatting Tips to learn how to format your message properly.

    Update : Oops - just noticed that your "$zero_screen" does exactly that already.

    Try Net::Telnet debugging, using input_log() or dump_log().

         Theory is when you know something, but it doesn't work.
        Practice is when something works, but you don't know why it works.
        Programmers combine Theory and Practice: Nothing works and they don't know why.         -Anonymous

      Thanks for the response. Yes I send the router the 'term len 0' command. I just tried the input_log and dump_log options and neither gave me an idea what to fix.
Re: perl Telnet.pm and Cisco.pm input buffer
by affc (Scribe) on Oct 29, 2009 at 23:51 UTC
    Hi,

    Can you show your script?