On Fri, 26 Feb 1999, Mark Delany wrote:

> Can I suggest printf's with %20s formating rather than \t
> 
> \t tends to look a bit ugly when, eg, domain names spread the stuff out over 
> multiple plages.
> 
> >    print "$_:\t$remote{$_} recips\t$remotebytes{$_} bytes\n";
> printf("%40s: %d recips, ...
> 
> Or even be very clever and note the length of the longest domain name.

Everyone's a critic :) Good idea. I'll make it so. New code at end.

I've also got a couple of other utils that you might like.

    qstatus - show continually updating (10 second cycle time) snapshot
    of the system (and it uses printf :) Example output (the leading /
    character rotates with each cycle, just so you can see things
    changing)

          queue             recipients      processes      tcpto     load
  processed/unprocessed    local/remote    local/remote      ips      avg
/        38           0        0     46        0      4        6     0.74

    recips - shows how many local and remote recipients there are:

        messages in queue: 38
        messages in queue but not yet preprocessed: 0
        0 local recipients
        45 remote recipients

    tcpto - attempts to resolve IP addresses from qmail-tcpto. Requires
    dnsptr from the qmail distribution:

hominet1.ruralco.com.au timed out 962 seconds ago; # recent timeouts: 1
m5.c2.telstra-mm.net.au timed out 443 seconds ago; # recent timeouts: 2
203.35.240.247 timed out 882 seconds ago; # recent timeouts: 1
gruyere.camtech.net.au timed out 762 seconds ago; # recent timeouts: 1
194.247.211.194 timed out 366 seconds ago; # recent timeouts: 1
igate1.mckinsey.com timed out 236 seconds ago; # recent timeouts: 1
fs-cls99.msl.com.au timed out 174 seconds ago; # recent timeouts: 1

I'll package them up and put them on an ftp site soon.

Regards
Peter
----------
Peter Samuel                                [EMAIL PROTECTED]
Technical Consultant                        or at present:
Uniq Professional Services,                 [EMAIL PROTECTED]
a division of X-Direct Pty Ltd
Phone: +61 2 9206 3410                      Fax: +61 2 9281 1301

"If you kill all your unhappy customers, you'll only have happy ones left"

###########################################################################
#!/usr/local/bin/perl -w
 
# Where is mail going?
 
use strict;
 
my $bytes = 0;
my $locals = 0;
my %local;
my %localbytes;
my $remotes = 0;
my %remote;
my %remotebytes;
 
my $newchars = 0;
my $oldchars = 0;
 
open(QREAD, "/var/qmail/bin/qmail-qread |");
 
while(<QREAD>)
{
    my @d;
    my @f;
 
    chomp;
    @f = split(' ');
 
    if (/\sGMT\s/)
    {
        $bytes = $f[6];
    }
 
    if ($f[0] eq "remote")
    {
        @d = split(/\@/, $f[1]);
        $d[1] = lc($d[1]);
        ++$remote{$d[1]};
        ++$remotes;
        $remotebytes{$d[1]} += $bytes;
        $newchars = length($d[1]);
        $oldchars = $newchars if ($newchars > $oldchars);
    }
 
    if ($f[0] eq "local")
    {
        @d = split(/\@/, $f[1]);
        $d[1] = lc($d[1]);
        ++$local{$d[1]};
        ++$locals;
        $localbytes{$d[1]} += $bytes;
        $newchars = length($d[1]);
        $oldchars = $newchars if ($newchars > $oldchars);
    }
}
 
print "Local Domains:\t", scalar keys %local;
print "\tLocal Recipients:\t$locals\n";
 
foreach (sort lnumerically keys %local)
{
    printf("%-${oldchars}.${oldchars}s %4d recips %9d bytes\n",
        $_, $local{$_}, $localbytes{$_});
}
 
print "\nRemote Domains:\t", scalar keys %remote;
print "\tRemote Recipients:\t$remotes\n";
 
foreach (sort rnumerically keys %remote)
{
    printf("%-${oldchars}.${oldchars}s %4d recips %9d bytes\n",
        $_, $remote{$_}, $remotebytes{$_});
}
 
sub lnumerically
{
    $local{$a} <=> $local{$b};
}
sub rnumerically
{
    $remote{$a} <=> $remote{$b};
}

Reply via email to