Advertisement
flaviolopes

captura-log

Jul 2nd, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.40 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use DateTime;
  7.  
  8. # Define e formata a Data de Busca
  9. my $dt  = DateTime->now->set_time_zone('America/Sao_Paulo');
  10. my $dia = $dt->day;
  11. my $mes = $dt->month_abbr;
  12. ##my $data = "$dia" . "-" . "$mes";
  13. my $data = "12-Jun";
  14.  
  15. my $arquivo_log  = "/var/log/log";
  16. my $falhas       = "/home/flavio/Scritps/err_execucao.sh";
  17. my $nao_executou = "/home/flavio/Scritps/nao_rodou.sh";
  18.  
  19. my @buffer;
  20.  
  21. open( my $file, "<", $arquivo_log )
  22.   or die "Erro ao abrir o arquivo: $!";
  23.  
  24. my $contador = 0;
  25. while (<$file>) {
  26.  
  27.     if ( $_ !~ /^$data/ ) {
  28.  
  29.         ## Nao faz nada!
  30.  
  31.     }
  32.  
  33.     else {
  34.  
  35.         $contador++;
  36.  
  37.     }
  38.  
  39. }
  40.  
  41. if ( $contador > 0 ) {
  42.  
  43.     open( my $file, "<", $arquivo_log )
  44.       or die "Erro ao abrir o arquivo: $!";
  45.  
  46.     while ( my $line = readline $file ) {
  47.  
  48.         next unless $line =~ /$data/;
  49.         $/ = undef;
  50.  
  51.         push @buffer, $line;
  52.  
  53.         foreach (@buffer) {
  54.  
  55.             if (   $_ =~ /\s*Non-fatal.*1/i
  56.                 or $_ =~ /\s*FD\s*termination.*Error/i
  57.                 or $_ =~ /\s*SD\s*termination.*Waiting/i
  58.                 or $_ =~ /\s*Canceled/i
  59.                 or $_ =~ /\^($data).*Unable to connect/i
  60.                 or $_ =~ /\^($data).*Open.*Device/i
  61.                 or $_ =~ /\^($data).*Could not open/i )
  62.             {
  63.  
  64.  
  65.                 system($falhas) == 0 or die "Erro ao executar: $?";
  66.  
  67.             }
  68.  
  69.         }
  70.     }
  71.  
  72. }
  73. else {
  74.  
  75.     # Envia mail dizendo que não houve backup no dia
  76.  
  77.     system($nao_executou) == 0 or die "Erro ao executar: $?";
  78.  
  79. }
  80.  
  81. close $file;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement