Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use POSIX qw(strftime);
- use IO::File;
- sub readLog {
- ## Aqui é a string de log
- ## Jun 18 16:43:25 sender-01 postfix/filter[12105]: 88E5620004DE9: FILTER_LOGX: from=<rodrigo@dominio.com.br> to=<jj@rrr.com.br> subject=<XXXXXX> size=26382 hostip=189.113.144.110 nrcpt=1
- my $pat = '^(... .. ..:..:..) (\S+) \S+ ([a-zA-Z0-9]+): FILTER_LOGX: from=\<(.*?)\> to=\<(.*?)\> subject=\<(.*?)\> size=([0-9]+) hostip=([^ ]*) nrcpt=([0-9]+)';
- my $fh;
- if (not sysopen($fh, "/var/log/mail.log", O_RDONLY)) {
- print $nl . " ... erro ao abrir PIPE \n";
- $nl = "";
- return '';
- }
- print $nl . " ... leitura de log iniciada \n";
- $nl = "";
- while (<$fh>) {
- chomp;
- if (m{$pat}) {
- $hora = $1;
- $server_name = $2;
- $msgid = $3;
- $from = lc $4;
- $to = lc $5;
- $subject = $6;
- $size = $7;
- $hostip = $8;
- $nrcpt = $9;
- #print "TIME=$1 SERVER=$2 ID=$3 FROM=$4 TO=$5 SUBJECT=$6 SIZE=$7 HOSTIP=$8 \n";
- #print "TIME=$hora SERVER=$server_name MSGID=$msgid FROM=$from TO=$to SUBJECT=$subject SIZE=$size HOSTIP=$hostip \n";
- print ($hora, $server_name, $msgid, $from, $to, $subject, $size, $hostip, $nrcpt);
- }
- }
- close $fh;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement