Mail Queu Summary Script

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Christoph Lameter
Dátum:  
Címzett: exim-users
Tárgy: Mail Queu Summary Script
Here is a script that summarizes the mail queue. Especially useful with
bigger queues:

Example:

mailq| mqs
Queue Summary
-------------

Host                                  Messages Volume    Oldest  Youngest


pacificcc.edu                               59  112KB       26h    8h
res2.resnet.upenn.edu                       45  107KB       28h    8h
saturn.math.uaa.alaska.edu                  19   39KB       38h    9h
hightech.edu                                17   33KB       15h    8h
foxy.uwc.edu                                 9   19KB       71h   13h
chartres.ee.tulane.edu                       8   15KB       26h   10h
moisil.wal.rhno.columbia.edu                 7   19KB        3d    3d
valhalla.cae.wisc.edu                        3   7680       30h    8h
waterf.org                                   1   2150        8d    8d



--- +++ --- +++ --- +++ --- +++ --- +++ --- +++ --- +++ ---
Please always CC me when replying to posts on mailing lists.
#!/usr/bin/perl

# Mail Queue Summary
# Christoph Lameter, 21 May 1997
#
# Usage: mailq|msq

# Slightly modified sub from eximstats

sub print_volume_rounded {
my($x) = pop @_;
if ($x < 10000)
  {
  return sprintf("%6d", $x);
  }
elsif ($x < 10000000)
  {
  return sprintf("%4dKB", ($x + 512)/1024);
  }
else
  {
  return sprintf("%4dMB", ($x + 512*1024)/(1024*1024));
  }
}

sub s_conv {
  my($x) = @_;
  my($v,$s)= $x =~ /([\d\.]+)(\w)+/;
  if ($s eq "K") { return $v * 1024 };
  if ($s eq "M") { return $v * 1024 * 1024 };
  return $v;
}

sub older {
  my($x1,$x2) = @_;
  my($v1,$s1)= $x1 =~ /(\d+)(\w)/;
  my($v2,$s2)= $x2 =~ /(\d+)(\w)/;

#  print "$v1 $s1 $v2 $s2\n";
  if ($s1 eq $s2) { return $v1 > $v2; };
  if ($s2 eq "m") { return 1; }
  if ($s2 eq "h" && $s1 eq "d") { return 1;}
  return 0;
}

#
# Main Program
#

while (<>)
{
if (/\s*D\s\S+/) { next; }
if (/^\s+[\w\d]*\@([\w\d\.]*)$/) {
  $queue{$1}++;
  if (!defined $q_oldest{$1} || &older($age,$q_oldest{$1})) {
    $q_oldest{$1}=$age;
    }
  if (!defined $q_recent{$1} || &older($q_recent{$1},$age)) {
    $q_recent{$1}=$age;
    }
  $q_size{$1} += &s_conv($size);
  }

if (/^([\d\s]{2}\w)\s+(\S+)\s(\S+)\s\<(\S*)\>$/) {
  ($age,$size,$id,$from)=($1,$2,$3,$4);
  }
}

print "\nQueue Summary";
print "\n-------------";
print "\n";
print "\nHost                                  Messages Volume    Oldest  Youngest\n\n"; 
foreach $id (sort { $queue{$b} <=> $queue{$a} } keys %queue) {
  printf ("%-40s %5d %-10s %5s %5s\n",
    $id,$queue{$id},&print_volume_rounded($q_size{$id}),$q_oldest{$id},$q_recent{$id});
}