[rancid] Re: wrong code with "Last configuration change at...."

Mathiruban Rajagopal mathiruban at gmail.com
Mon Nov 16 14:06:06 UTC 2009


Hi,

Which file I have to edit?
I am not getting the last config change for cisco routers.

Mathy.



2009/9/25 Iñaki Martinez Diez <networking at hostalia.com>

> Hi,
>
>  I want to log the lines:
>
>  ! Last configuration change at 12:50:31 GMT Fri Sep 25 2009 by xxxxx
>  ! NVRAM config last updated at 08:35:27 GMT Fri Sep 25 2009 by xxxxx
>
>
>  But this code is wrong:
>
> 1488 # This routine processes a "write term"
> 1489 sub WriteTerm {
> 1490     print STDERR "    In WriteTerm: $_" if ($debug);
> 1491     my($lineauto,$comment,$linecnt) = (0,0,0);
> 1492
> 1493     while (<INPUT>) {
> 1494         tr/\015//d;
> 1495         last if (/^$prompt/);
> 1496         return(1) if /Line has invalid autocommand /;
> 1497         return(1) if (/(Invalid input detected|Type help or )/i);
> 1498         return(0) if ($found_end);              # Only do this
> routine once
> 1499         return(-1) if (/command authorization failed/i);
> 1500         # the pager can not be disabled per-session on the PIX
> 1501         if (/^(<-+ More -+>)/) {
> 1502             my($len) = length($1);
> 1503             s/^$1\s{$len}//;
> 1504         }
> 1505
> 1506         /Non-Volatile memory is in use/  && return(-1); # NvRAM is
> locked
> 1507         $linecnt++;
> 1508         $lineauto = 0 if (/^[^ ]/);
> 1509         # skip the crap
> 1510         if (/^(##+$|(Building|Current) configuration)/i) {
> 1511             while (<INPUT>) {
> 1512                 next if (/^Current configuration\s*:/i);
> 1513                 next if (/^:/);
> 1514                 next if (/^([%!].*|\s*)$/);
> 1515                 next if (/^ip add.*ipv4:/);     # band-aid for 3620
> 12.0S
> 1516                 last;
> 1517             }
> 1518             if (defined($config_register)) {
> 1519                 ProcessHistory("","","","!\nconfig-register
> $config_register\n");
> 1520             }
> 1521             tr/\015//d;
> 1522         }
> 1523         # some versions have other crap mixed in with the bits in the
> 1524         # block above
> 1525         /^! (Last configuration|NVRAM config last)/ && next;
> 1526
>
>  Although i commented the line 1525 the lines above are NEVER logged
> because the "while" loop in the line 1511 ignore and the two lines are
> never processed by line 1525, so i made this changes:
>
> 1488 # This routine processes a "write term"
> 1489 sub WriteTerm {
> 1490     print STDERR "    In WriteTerm: $_" if ($debug);
> 1491     my($lineauto,$comment,$linecnt) = (0,0,0);
> 1492
> 1493     while (<INPUT>) {
> 1494     tr/\015//d;
> 1495     last if (/^$prompt/);
> 1496     return(1) if /Line has invalid autocommand /;
> 1497     return(1) if (/(Invalid input detected|Type help or )/i);
> 1498     return(0) if ($found_end);      # Only do this routine once
> 1499     return(-1) if (/command authorization failed/i);
> 1500     # the pager can not be disabled per-session on the PIX
> 1501     if (/^(<-+ More -+>)/) {
> 1502         my($len) = length($1);
> 1503         s/^$1\s{$len}//;
> 1504     }
> 1505
> 1506     /Non-Volatile memory is in use/  && return(-1); # NvRAM is locked
> 1507     $linecnt++;
> 1508     $lineauto = 0 if (/^[^ ]/);
> 1509     # skip the crap
> 1510     if (/^(##+$|(Building|Current) configuration)/i) {
> 1511         while (<INPUT>) {
> 1512         if (/^! (Last configuration|NVRAM config last)/) {
> 1513             ProcessHistory("","","",$_);
> 1514             next;
> 1515         }
> 1516         next if (/^Current configuration\s*:/i);
> 1517         next if (/^:/);
> 1518         next if (/^([%!].*|\s*)$/);
> 1519         next if (/^ip add.*ipv4:/); # band-aid for 3620 12.0S
> 1520         last;
> 1521         }
> 1522         if (defined($config_register)) {
> 1523         ProcessHistory("","","","!\nconfig-register
> $config_register\n");
> 1524         }
> 1525         tr/\015//d;
> 1526     }
> 1527     # some versions have other crap mixed in with the bits in the
> 1528     # block above
> 1529
>
>  So now the two lines are logged and emailed.
>
>  I hope this can help somebody.
>
>
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20091116/e83adab0/attachment.html 


More information about the Rancid-discuss mailing list