2011年4月12日 星期二

scan log file in perl - another version

modify again, use egrep command to parse log directory.
修改另一各版本,用egrep指令+正規表示式來搜尋關鍵字
##########################################################
use strict;
use diagnostics;

### Variables defined here ###
my $domain = "abc.com"; # used in mail sender
chomp(my $host = "" || "localhost"); # hostname
my $DIR = "/WebSphere/AppServer/profiles/appsrv/logs"; # log directory
my $l_log = "SystemOut"; # log name
my $SENDMAIL = '/usr/sbin/sendmail';
### regular express here ###
my $keyword = 'SystemErr|dump';
### use , to seperate and put \ before @  ###
my $Admins = "abc\@abc.com";

### main logistic here ###
my $filename = $l_log . "*.log";
my @l_log = process_log($filename, $keyword);
if ( scalar @l_log > 0 ) {
&write_mail();
}
exit; # jump out...

### functions here ###
sub process_log {
my $target_log  = shift;
my $search_data = shift;

my $CMD = "/usr/bin/egrep -e '" . $search_data . "' " . $DIR . "/" . $filename;
my @RES = `$CMD`;
return @RES;
}

sub write_mail {
open (MAIL, "|$SENDMAIL -t") || die ("$0: Can't open $SENDMAIL: $!\n");
print MAIL "Reply-to: root\@$host.$domain\n";
print MAIL "From: \"$host Log\" \\n";
print MAIL "To: $Admins\n";
print MAIL "Subject: [Notice] $host Error Log Report at ", scalar localtime, "\n";
print MAIL " report from " . $host . ":\n";
print MAIL "\n$filename -\n";
foreach (@l_log) {print MAIL "$_\n"};
close (MAIL);
}

沒有留言:

20171016 股海人生紀錄之單日漲幅新高

鬼混股海這麼多年來這一次還是很值得紀錄,我手上股票單一交易日漲了92.47%(盤後還繼續漲了12.46%)。 深深覺得美股比台股有魅力多了啊~ 以下轉貼原本寫在mobile01上面的推薦文: 所以我就一篇把相關研究過的訊息寫一寫吧 這應該是trxc第一篇中...