前端之家收集整理的这篇文章主要介绍了
Perl 监控日志异常报警,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<pre name="code" class="sql">#!/usr/bin/perl
while (1==1){
$dir='/root/log';
$file_tmp = `cd $dir; ls -ltr logs.log* | tail -1 `;
$file = (split/\s+/,"$file_tmp")[8];
$mon_file="$dir/$file",print "\$mon_file is $mon_file\n";
open (C,"<","$file.tmp");
while (<C>){
$count = $_;
}
print "\$count is $count\n";
$info =`tac $mon_file | grep excep | head -1`;
open (A,"$mon_file") || die "$!\n";
$i=0;
while (<A>) {
if ( $_ =~/exception/i){$i++};
}
if ($i > $count) {print "error--$info\n";};
open (B,">","$file.tmp");
print B ("$i\n");
sleep (10);
}