系统管理工具包: 过滤电子邮件中的垃圾邮件和病毒
2008-11-11 08:28:08 来源:WEB开发网清单 3. 提取日志输出的 Perl 脚本
#!/usr/bin/perl
my $stats = {};
while(<STDIN>)
{
chomp;
next unless (m{/usr/bin/amavisd[d+]: (d+-d{2})});
if (m/(Passed|Blocked) [A-Z]+/)
{
my ($proc_mode,$proc_type) = (m/(Passed|Blocked) ([-A-Z]+)/);
$stats->{$proc_mode}->{$proc_type}++;
}
}
foreach my $mode (sort keys %{$stats})
{
my $modetotal = 0;
print "$moden";
foreach my $type (sort keys %{$stats->{$mode}})
{
printf("t%-20s %7dn",$type,$stats->{$mode}->{$type});
$modetotal += $stats->{$mode}->{$type};
}
printf("t%-20s %7dn",'Total',$modetotal);
}
To run the script we pipe the contents of the file through the script:
$cat amavis.log |perl parse_amavis.pl
Blocked
BANNED 32793
CLEAN 1
INFECTED 766
SPAM 85499
Total 119059
Passed
BAD-HEADER 1415
CLEAN 70588
SPAM 356
Total 72359
很不幸的是,从以上内容中可以看出,在接收到的电子邮件中,超过 62% 的电子邮件受到了阻止,因为它们是垃圾邮件。
更多精彩
赞助商链接