postfix日志每天发送情况统计
2017/11/17 14:05:49 点击:
#!/usr/bin/perl
use POSIX qw(strftime);
my $mon = strftime("%b",localtime(time()-86400));
my $day = strftime("%d",localtime(time()-86400));
my $yesterday = strftime("%Y%m%d",localtime(time()-86400));
my %success;
my %all;
my $dom = shift || "";
my @f = </var/log/maillog*>;
my $last_file = (map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ (stat($_))[9], $_ ] } @f)[0];
my $pat_one = qr/$mon/s+$day.*?to=<(.*?/@(?:[^.]+/.)*$dom[^>]*)>.*?status=sent/x;
my $pat_two = qr{$mon/s+$day.*?to=<(.*?/@(?:[^.]+/.)*$dom[^>]*)>.*?}x;
open LOG,$last_file;
while(<LOG>) {
if (/$pat_one/) {
$success{$1}++;
}
if (/$pat_two/) {
$all{$1}++;
}
}
close LOG;
最后对 %success,%all操作,可以写到文本,可以记录到数据库等等
运行: xxx.pl domain_name
例如:a.pl sohu.com
use POSIX qw(strftime);
my $mon = strftime("%b",localtime(time()-86400));
my $day = strftime("%d",localtime(time()-86400));
my $yesterday = strftime("%Y%m%d",localtime(time()-86400));
my %success;
my %all;
my $dom = shift || "";
my @f = </var/log/maillog*>;
my $last_file = (map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ (stat($_))[9], $_ ] } @f)[0];
my $pat_one = qr/$mon/s+$day.*?to=<(.*?/@(?:[^.]+/.)*$dom[^>]*)>.*?status=sent/x;
my $pat_two = qr{$mon/s+$day.*?to=<(.*?/@(?:[^.]+/.)*$dom[^>]*)>.*?}x;
open LOG,$last_file;
while(<LOG>) {
if (/$pat_one/) {
$success{$1}++;
}
if (/$pat_two/) {
$all{$1}++;
}
}
close LOG;
最后对 %success,%all操作,可以写到文本,可以记录到数据库等等
运行: xxx.pl domain_name
例如:a.pl sohu.com
- 上一篇:不错的RPM资源网站 [2017-11-18]
- 下一篇:Postfix邮件的备份方法 [2017-11-17]