日志
>>>>>>>/data/apps/meganotes/tomcat/logs/app/app.log.2009-02-18<<<<<<<<<
error number :>>2<<
MusicActionOpLogProxy:142 - music.popularTime=[Invalid field value for field "music.popularTime".]
2009-02-18 15:53:54, 2009-02-18 16:00:12
#
!/bin/perl
use Encode ;
open (NOTESFILES , $ARGV [ 0 ]);
my %errorMeganotes ;
print " >>>>>>>>>>>>>> " , $ARGV [ 0 ] , " <<<<<<<<<<\n " ;
while ( < NOTESFILES > ) {
if ( $_ =~/^ ( \ d{ 4 } -\ d{ 2 } -\ d{ 2 } \ s \ d{ 2 } :\ d{ 2 } :\ d{ 2 }) \ s + ERROR \ s + ( .* ) \ s / g ){
if ( $errorMeganotes {$ 2 }){
push @{ $errorMeganotes {$ 2 }} , $ 1 ;
} else {
$errorMeganotes {$ 2 } = [$ 1 ];
}
}
}
for ( keys %errorMeganotes ){
my $tmp_keys = $_ ;
my @tmp_array = @{ $errorMeganotes { $tmp_keys }};
print " error number :>> " , scalar ( @tmp_array ) , " <<\n " , encode( " GBK " , decode( " UTF-8 " , $tmp_keys )) , " \n " , join ( " ,\t " , @tmp_array ) , " \n\n\n " ;
}
sh
use Encode ;
open (NOTESFILES , $ARGV [ 0 ]);
my %errorMeganotes ;
print " >>>>>>>>>>>>>> " , $ARGV [ 0 ] , " <<<<<<<<<<\n " ;
while ( < NOTESFILES > ) {
if ( $_ =~/^ ( \ d{ 4 } -\ d{ 2 } -\ d{ 2 } \ s \ d{ 2 } :\ d{ 2 } :\ d{ 2 }) \ s + ERROR \ s + ( .* ) \ s / g ){
if ( $errorMeganotes {$ 2 }){
push @{ $errorMeganotes {$ 2 }} , $ 1 ;
} else {
$errorMeganotes {$ 2 } = [$ 1 ];
}
}
}
for ( keys %errorMeganotes ){
my $tmp_keys = $_ ;
my @tmp_array = @{ $errorMeganotes { $tmp_keys }};
print " error number :>> " , scalar ( @tmp_array ) , " <<\n " , encode( " GBK " , decode( " UTF-8 " , $tmp_keys )) , " \n " , join ( " ,\t " , @tmp_array ) , " \n\n\n " ;
}
#
!/bin/sh
nowDate = $(date - d ' -1 day ' +% Y -% m -% d);
echo $nowDate
perl / data / apps / shell / meganotesErrorLog.pl / data / apps / meganotes / tomcat / logs / app / app.log.$nowDate > _tmp_$nowDate ;
perl / data / apps / shell / meganotesErrorLog.pl / data / apps / schedule / tomcat / logs / app / app.log.$nowDate >> _tmp_$nowDate ;
mail - s $nowDate - ERROR - log my@mail.com < _tmp_$nowDate;
rm _tmp_$nowDate ;
结果:
nowDate = $(date - d ' -1 day ' +% Y -% m -% d);
echo $nowDate
perl / data / apps / shell / meganotesErrorLog.pl / data / apps / meganotes / tomcat / logs / app / app.log.$nowDate > _tmp_$nowDate ;
perl / data / apps / shell / meganotesErrorLog.pl / data / apps / schedule / tomcat / logs / app / app.log.$nowDate >> _tmp_$nowDate ;
mail - s $nowDate - ERROR - log my@mail.com < _tmp_$nowDate;
rm _tmp_$nowDate ;
>>>>>>>/data/apps/meganotes/tomcat/logs/app/app.log.2009-02-18<<<<<<<<<
error number :>>2<<
MusicActionOpLogProxy:142 - music.popularTime=[Invalid field value for field "music.popularTime".]
2009-02-18 15:53:54, 2009-02-18 16:00:12
。。。。。。
本文转自博客园刘凯毅的博客,原文链接:log4j perl 错误日志提取,如需转载请自行联系原博主。