Advertisement
Guest User

Get_Log.pl

a guest
Jun 18th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.32 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4. use strict;
  5. use POSIX qw(strftime);
  6. use IO::File;
  7.  
  8.  
  9. sub readLog {
  10.  
  11. ## Aqui é a string de log 
  12. ## 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
  13.  
  14. my $pat = '^(... .. ..:..:..) (\S+) \S+ ([a-zA-Z0-9]+): FILTER_LOGX: from=\<(.*?)\> to=\<(.*?)\> subject=\<(.*?)\> size=([0-9]+) hostip=([^ ]*) nrcpt=([0-9]+)';
  15.     my $fh;
  16.     if (not sysopen($fh, "/var/log/mail.log", O_RDONLY)) {
  17.         print $nl . " ... erro ao abrir PIPE \n";
  18.         $nl = "";
  19.         return '';
  20.     }
  21.     print $nl . " ... leitura de log iniciada \n";
  22.     $nl = "";
  23.  
  24.  
  25.     while (<$fh>) {
  26.       chomp;
  27.       if (m{$pat}) {
  28.            $hora = $1;
  29.            $server_name = $2;
  30.            $msgid = $3;
  31.            $from = lc $4;
  32.            $to = lc $5;
  33.            $subject = $6;
  34.            $size = $7;
  35.            $hostip = $8;
  36.            $nrcpt = $9;
  37.          #print "TIME=$1 SERVER=$2 ID=$3 FROM=$4 TO=$5 SUBJECT=$6 SIZE=$7 HOSTIP=$8 \n";
  38.          #print "TIME=$hora SERVER=$server_name MSGID=$msgid FROM=$from TO=$to SUBJECT=$subject SIZE=$size HOSTIP=$hostip \n";
  39.          print ($hora, $server_name, $msgid, $from, $to, $subject, $size, $hostip, $nrcpt);
  40.       }
  41.     }
  42.  
  43.     close $fh;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement