JWK - Jackall's IT Wiki

Sécurité, Système, Réseau

Outils pour utilisateurs

Outils du site


findmail

Here is a PERL script to find all lines related to a specific mail in your postfix and antivirus (Amavis) log.

The script is pretty “quick and dirty” i.e easy to use. You just have to call the script passing the mail headers and path to the log files.

Code

#!/usr/bin/perl -w
#use strict;
# (1) quit unless we have the correct number of command-line args
my $num_args = $#ARGV + 1;
if ($num_args != 3){
  print "\nUsage: ".$ARGV[0]." mail_header_file mail_log virus_log\n";
  exit;
}
 
else {
        my @tab_id;
        my $file = $ARGV[0];
        my $maillog = $ARGV[1];
        my $viruslog = $ARGV[2];
 
        open( $fh,"$file");
        if ($fh) {
 
                while (my $line = <$fh>) {
                        if ($line =~ /id (\w*)\s+/){
                                push(@tab_id,"$1");
 
                        }
                }
 
                for my $id (reverse(@tab_id)){
                        system("grep","-i","$id","$maillog","$viruslog");
                }
 
                close($fh);
        }
}

search?q=perl%20postfix%20script%20EN&amp;btnI=lucky

findmail.txt · Dernière modification: 2018/02/18 16:01 (modification externe)