[rancid] [PATCH] Reduce chatter about file sizes in nvram.

Alan McKinnon alan.mckinnon at gmail.com
Fri Jun 6 23:09:23 UTC 2014


Hi,

I got tired of endless noise mails with diffs like this:


- !Flash: nvram:  1692  -rw-      356089                    <no date>
startup-config
+ !Flash: nvram:  1692  -rw-      356257                    <no date>
startup-config
- !Flash: nvram: 2093048 bytes total (1636661 bytes free)
+ !Flash: nvram: 2093048 bytes total (1636493 bytes free)

So I wrote the below to deal with it.
Rationale: I don't care to know that the file increased by 168 bytes,
all I want to know is if the file was created or deleted and it's
approximate size. I'd also like to know if the size changed dramatically
eg 100K to 10M.
The patch transforms the size to the nearest SI unit and truncates it to
an integer, like so:

!Flash: nvram:  1691  -rw-       347KB                    <no date>
startup-config
!Flash: disk0:        1MB bytes total (       1MB bytes free)


The diff is against 2.3.8 and I have similar ones for nxrancid and
xrrancid. Also gsrrancid but that's my own creation for GSRs and not in
the source tarballs.





--- rancid.old  2014-05-16 01:07:20.000000000 +0200
+++ rancid      2014-06-04 01:47:20.000000000 +0200
@@ -95,6 +95,24 @@
     1;
 }

+# Transform filesizes into integral SI units (eg 123456 => 120KB)
+sub numtosi {
+    my $num = $_[0];
+    my $len = length($_[0]);
+    if ($num >= (1024 * 1024 * 1024)) {
+        $num = int($num / (1024 * 1024 * 1024));
+        return sprintf("%$len"."s", "$num"."GB");
+    } elsif ($num >= (1024 * 1024 )) {
+        $num = int($num / (1024 * 1024));
+        return sprintf("%$len"."s", "$num"."MB");
+    } elsif ($num >= (1024 )) {
+        $num = int($num / (1024));
+        return sprintf("%$len"."s", "$num"."KB");
+    } else {
+        return $num;
+    }
+}
+
 sub numerically { $a <=> $b; }

 # This is a sort routine that will sort numerically on the
@@ -717,6 +736,14 @@
        # Filter dhcp database
        next if (/dhcp_[^. ]*\.txt/);

+        # Transform file sizes in file listing to SI units
+        if (/^(\s*?\d+\s+[rwx-]{4}\s+)(\d+)(.*)/) {
+            $_ = "$1" . numtosi($2) . "$3\n";
+        }
+       if (/^(\s*?)(\d+) bytes total \((\d+) bytes free\)$/) {
+           $_ = $1 . numtosi($2) . " bytes total (" . numtosi($3) . "
bytes free)\n";
+       }
+
        /\s+(multiple-fs|nv_hdr|vlan\.dat)$/ && next;
        ProcessHistory("FLASH","","","!Flash: $_");
     }
@@ -762,22 +789,19 @@
        # Filter dhcp database
        next if (/dhcp_[^. ]*\.txt/);

-       if ($ios eq "XE" && /.*\((\d+) bytes free\)/) {
-           my($tmp) = $1;
-           if ($tmp >= (1024 * 1024 * 1024)) {
-               $tmp = int($tmp / (1024 * 1024 * 1024));
-               s/$1 bytes free/$tmp GB free/;
-           } else {
-               $tmp = int($tmp / (1024 * 1024));
-               s/$1 bytes free/$tmp MB free/;
-           }
-       }
        if ($ios eq "XE" && /^((\s+)?\d+\s+\S+)\s+\d+.*(tracelogs$)/) {
            $_ = "$1" . sprintf("%43s", "") . "$3\n";
        }
        if ($ios eq "IOS" && /^((\s+)?\d+\s+\S+)\s+\d+.*(sflog$)/) {
            $_ = "$1" . sprintf("%43s", "") . "$3\n";
        }
+        # Transform file sizes in file listing to SI units
+        if (/^(\s*?\d+\s+[rwx-]{4}\s+)(\d+)(.*)/) {
+            $_ = "$1" . numtosi($2) . "$3\n";
+        }
+       if (/^(\s*?)(\d+) bytes total \((\d+) bytes free\)$/) {
+           $_ = $1 . numtosi($2) . " bytes total (" . numtosi($3) . "
bytes free)\n";
+       }
        # the pager can not be disabled per-session on the PIX
        if (/^(<-+ More -+>)/) {
            my($len) = length($1);




-- 
Alan McKinnon
alan.mckinnon at gmail.com



More information about the Rancid-discuss mailing list