Postfix queue monitoring script

Here is a small Perl script which can be useful as a Postfix queue monitor (count number of emails in Postfix queue)

#!/usr/bin/env perl   # postfix queue/s size # author: # source: http://tech.groups.yahoo.com/group/postfix-users/message/255133   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,}$  }) {                         ++$  c;                 } 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`; chomp($  qdir); chdir($  qdir) or die "$  0: chdir: $  qdir: $  !n"; printf "Incoming: %dn", count("incoming"); printf "Active: %dn", count("active"); printf "Deferred: %dn", count("deferred"); printf "Bounced: %dn", count("bounce"); printf "Hold: %dn", count("hold"); printf "Corrupt: %dn", count("corrupt");

Save script as queueStatus (for example), chmod +x to make it exec, and output

[[email protected] tmp]# ./queueStatus  Incoming: 0 Active: 0 Deferred: 8 Bounced: 6 Hold: 0 Corrupt: 0