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);
}

FBI and UFO

話說今天吃晚餐的時候看到電視在說FBI公佈了解密文件證實外星人曾經墜落地球。想了一下才知道記者是在說Roswell,不由得有點吃驚,美國政府承認這件事,那豈不是造成大騷動了? 但是看到電視畫面都是電影....(下面是TVBS的影片)


回到家後google了一下發現,英文網頁上確實有不少提到這件事,但是卻沒有大型媒體報導;倒是facebook網頁不少(個人發表)。於是直接到傳聞中的FBI: the vault網站看看,這一看卻是啼笑皆非。

首先,FBI網站上有篇文章在說明這事件。
The FBI and UFOs
這網頁的最大價值在於有flying dishs的照片。
以及公佈的文件電子檔 UFO Part 1 of 16 這一份文件有69頁的原始資料,其中在第17頁有段文字描寫這flying saucers

所以從FBI公佈的資料看來,所謂羅斯威爾UFO,其實是美國空軍的高空雷達實驗器材。當然這個說法早在當年就是這樣公告的,信者恆信。認為當年真有飛碟墜毀的人也只會認為這些文件是美國政府假造的。

只是,今天幾乎每家媒體都報的不亦樂乎。這麼多記者當中就沒有人讀得懂英文?沒人去FBI:the vault上面看看原始文件? (搖頭)

2011年4月11日 星期一

Sourcecode - 啟動原始碼


結論放最前面:好看。頗有創意的電影。

裡面的source code計畫其實是套用量子力學理論,量子等級的小物體有無限的可能路徑,甚至會自己干擾自己。這邊就不多說了,有興趣的人可以去看霍金的大創造,裡面有很淺顯易懂的解釋。有趣的是,電影中卻避而不談如何讓已死的上尉和Sean這歷史老師產生連結,可能要用專利所在無法公開才能掩飾得過去。

當然電影的主題從不會放在生冷的科技與量子力學理論上面,而是在人身上,特別是男女間的愛情更是重點中的重點。所以這麼剛好這個歷史老師就是跟位不知來歷的年輕女子一起搭火車,還是兩人互有好感。然後最重要得是這句話,當你的生命只剩下八分鐘,你要做什麼?

雖然一次兩次很感人,但是重複上六七次的八分鐘,就像是電動中打不過的關卡,還挺沉悶的。 =.=
而且看到最後覺得好人方面有作弊的fu。 XD

配樂配合得很適當,讓整各劇情流暢度加分不少;男女主角的演技也很生動,算是部值得一看的電影。不過就像一般娛樂電影,很多嚴肅的議題都是輕輕帶過,像是已經陣亡的士兵,用科技來延長「使用時限」的道德討論。而平行世界彼此間交互影響的可能性,就是因為帶的太過輕易,反而讓最後結尾一小段大家看不懂。

scan log file in perl

rewrite an old script to run on linux and scan for jboss log
used for hourly scan this hours' log
把幾年前用的script又搬出來改寫,好符合現在的環境,並且可以指定任意log檔
每小時59分parse一次,會去檢查這一小時的log
但是沒很漂亮,可能不同環境還是要修改
##################################################################

#!/usr/bin/perl -w

use strict;
use diagnostics;

### Variables defined here ###
my $domain = ""; # used in mail sender
chomp(my $host = "" || "localhost"); # hostname
my $DIR = "/jboss/logs"; # log directory
my $l_log = "server.log"; # log name
my $SENDMAIL = '/usr/lib/sendmail';
### regular express here ###
my $keyword = '( ERROR )';
### use , to seperate and put \ before @  ###
my $Admins = "aaa\@abc.com";

### Date & time ###
my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime;
my $today = sprintf("%04d", $year+1900) . "-" . sprintf("%02d", $mon+1) . "-" . sprintf("%02d", $mday); # get day

### main logistic here ###
### this line because the log name like system.log.2011-04-11 ###
my $filename = $DIR . "/" . $l_log . "." . $today;
my @l_log = process_log($filename, $hour, $keyword);
if ( scalar @l_log > 0 ) {
&write_mail();
}
exit; # jump out...

### functions here ###
sub process_log {
my $target_log  = shift;
my $search_time = sprintf("%02d", shift);
my $search_data = shift;
open (MY_LOGS, "$filename") or die "Can't find $filename: $!";
while () {
      chomp; # no newline...
      s/#.*//; # no comments...
      s/^\s+//; # no leading whitespace...
      s/\s+$//; # no trailing whitespace...
      next unless length; # anything to process?
      next unless /\s$search_time:"/; # only this hour
      next unless /\s$search_data\s/;
      push(@_,$_);
      }
return @_;
}

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: $host Jboss 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);
}

最常被訪