Select Page

The following Perl script gets the size of the Postfix Active queue and outputs it.
(Used for queue monitoring on our NMS via SSH sensors, but might be useful in your environment)

#!/usr/bin/env perl
use strict;
use warnings;
use Symbol;
sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die "$0: opendir: $dir: $!\n";
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count("$dir/$f");
closedir($dh) or die "closedir: $dir: $!\n";
return $c;
my $qdir = `postconf -h queue_directory`;
chdir($qdir) or die "$0: chdir: $qdir: $!\n";
printf count("active\n");

The output from this is extremely short – just the queue size, nothing else.

[root@home kscripts]# ./
[root@home kscripts]#