Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
tuto:ipasserelle:divers:script_recherche_maillog [13/10/2017 18:35] dani supprimée |
tuto:ipasserelle:divers:script_recherche_maillog [14/11/2018 09:59] heuzef |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Script de recherche maillog ====== | ||
+ | Dans certain cas, effectuer une recherche de mail bien précise dans des archives maillog très volumineuse s’avère trop complexe, bien souvent la machine exploitée ou le client email pour cette recherche n'est pas assez performant pour supporter la charge. | ||
+ | |||
+ | Voici une base de script perl à exécuter directement pour copier les emails trouvé directement. Ce script réclame plusieurs heures à l' | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | <file perl maillog_search.pl> | ||
+ | |||
+ | # | ||
+ | |||
+ | use strict; | ||
+ | use warnings; | ||
+ | use File::Find; | ||
+ | use Email:: | ||
+ | use Email:: | ||
+ | use Data:: | ||
+ | use File::Copy; | ||
+ | |||
+ | my $dir = '/ | ||
+ | my @from = qw(< | ||
+ | my @to = qw(< | ||
+ | my $res = '/ | ||
+ | my @domains = qw( | ||
+ | < | ||
+ | ); | ||
+ | my $cnt_total = 0; | ||
+ | my $cnt_matched = 0; | ||
+ | find(\& | ||
+ | |||
+ | sub search { | ||
+ | my $file = $_; | ||
+ | print " | ||
+ | return unless -f $file; | ||
+ | return if $file =~ m/^dovecot/ || $file eq ' | ||
+ | $cnt_total++; | ||
+ | my $content; | ||
+ | open F, $file; | ||
+ | $content .= $_ while(< | ||
+ | close F; | ||
+ | # print " | ||
+ | my $email = Email:: | ||
+ | my ($from_header) = Email:: | ||
+ | return unless $from_header; | ||
+ | my @to_header = Email:: | ||
+ | my @cc_header = Email:: | ||
+ | if (grep { $_ eq $from_header-> | ||
+ | if (grep { $_ eq $from_header-> | ||
+ | $cnt_matched++; | ||
+ | copy $file, $res . ' | ||
+ | print $file . " matched (from)\n"; | ||
+ | } | ||
+ | } | ||
+ | foreach my $addr (@to_header){ | ||
+ | if (grep { $_ eq $addr-> | ||
+ | if (grep { $addr-> | ||
+ | $cnt_matched++; | ||
+ | copy $file, $res . ' | ||
+ | print $file . " matched (to)\n"; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | foreach my $addr (@cc_header){ | ||
+ | if (grep { $_ eq $addr-> | ||
+ | if (grep { $addr-> | ||
+ | $cnt_matched++; | ||
+ | copy $file, $res . ' | ||
+ | print $file . " matched (cc)\n"; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | print "Found $cnt_matched file (out of $cnt_total)\n"; | ||
+ | |||
+ | </ |