mik*_*ers 16
这是我使用的,从 postfix 邮件列表中挑选出来的。我删除了作者的名字,以防他不想要这里(你可以在源代码中看到)。它只显示总数。
#!/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: %d\n", count("incoming");
printf "Active: %d\n", count("active");
printf "Deferred: %d\n", count("deferred");
printf "Bounced: %d\n", count("bounce");
printf "Hold: %d\n", count("hold");
printf "Corrupt: %d\n", count("corrupt");
Run Code Online (Sandbox Code Playgroud)
编辑:修正了第 26 行的一个错字。
小智 6
[root@server ~]# time mailq | grep -c '^[0-9A-Z]'
10
真正的 0m1.333s
用户 0m0.003s
系统 0m0.003s
(以上结果表示有 10 封邮件在排队)
如果没有qshape
,可以通过以下 yum 命令安装它:
yum groupinstall perl development
yum install postfix-perl-scripts
qshape 打印 Postfix 队列域和年龄分布信息。你可以在这里读更多关于它的内容:
http://www.postfix.org/QSHAPE_README.html
% qshape -s hold | head
T 5 10 20 40 80 160 320 640 1280 1280+
TOTAL 486 0 0 1 0 0 2 4 20 40 419
yahoo.com 14 0 0 1 0 0 0 0 1 0 12
extremepricecuts.net 13 0 0 0 0 0 0 0 2 0 11
ms35.hinet.net 12 0 0 0 0 0 0 0 0 1 11
winnersdaily.net 12 0 0 0 0 0 0 0 2 0 10
hotmail.com 11 0 0 0 0 0 0 0 0 1 10
worldnet.fr 6 0 0 0 0 0 0 0 0 0 6
ms41.hinet.net 6 0 0 0 0 0 0 0 0 0 6
osn.de 5 0 0 0 0 0 1 0 0 0 4
Run Code Online (Sandbox Code Playgroud)