Fwd: Patch to sendmail-largeboxes

Kirk Bauer <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
---------- Forwarded message ----------
From: "Moray Henderson (ICT)" <[email protected]>
Date: Mon, 1 Mar 2010 17:06:50 +0000
Subject: Patch to sendmail-largeboxes
To: "[email protected]" <[email protected]>

Hi there,

Attached is a patch against sendmail-largeboxes from the
logwatch-7.3-6.el5 rpm from CentOS.  It sorts the output according to
mailbox size, aligns it neatly, and displays the sizes in
human-readable format.

Hope you find it useful.


Moray.
"To err is human.  To purr, feline"



-- 
Sent from my mobile device


------------------------------------------------------
Kirk Bauer <[email protected]>
http://linux.kaybee.org | www.logwatch.org
Author, Automating UNIX & Linux Administration

_______________________________________________
Logwatch-Devel mailing list
[email protected]
http://www2.list.logwatch.org:81/mailman/listinfo/logwatch-devel
sendmail-largeboxes.patch (application/octet-stream, 1.5 KB)
--- /usr/share/logwatch/scripts/services/sendmail-largeboxes    2008-05-24 17:42:04.000000000 +0100
+++ /etc/logwatch/scripts/services/sendmail-largeboxes  2010-03-01 16:36:28.000000000 +0000
@@ -5,6 +5,17 @@
 use strict;
 use POSIX;

+sub convert_bytes ($$){
+       my ($bytes, $dec) = @_;
+
+       foreach my $posfix (qw(bytes KB MB GB TB PB EB ZB YB)) {
+               if ($bytes < 1024)     {
+                       return sprintf("%.${dec}f%s", $bytes, $posfix);
+               }
+               $bytes /= 1024;
+       }
+}
+
 my $SPOOLDIR = '';
 my $sizethresh = defined $ENV{sendmail_largeboxes_size} ? uc $ENV{sendmail_largeboxes_size} : 40960000;
 my $title = "Large Mailbox threshold: $sizethresh";
@@ -38,11 +49,15 @@
        my @files = grep {!/^\./} readdir(DIR);
        closedir DIR;

+       my %largeboxes;
        for my $filename (@files) {
                my $checksize = (stat("$SPOOLDIR/$filename"))[7];
                if ($checksize >= $sizebytes) {
-                       print "$title Warning: Large mailbox: $filename ($checksize)\n";
-                       $title = "";  # only print at start of report
+                       $largeboxes{$filename} = $checksize;
                }
        }
+       for my $filename (sort {$largeboxes{$b} <=> $largeboxes{$a}} keys %largeboxes) {
+               printf "$title Warning: Large mailbox: %-20s (%9s)\n", $filename, convert_bytes($largeboxes{$filename}, 1);
+               $title = "";  # only print at start of report
+       }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.