« [公告] IPCN 全部服务现在不可用 | Main | 最新进展 Re: 我的域名倒闭了 »
January 24, 2006
[PERL] filter log, simple, it does work
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。 https://windtear.net/archives/2006/01/24/000896.html http://windtear.net/archives/2006/01/24/000896.html [PERL] filter log, simple, it does work 之前用c写了一个 测试是work的 真正用的的时候不work 就临时写了一个perl 没加参数判断地容错性 呵呵 按我的习惯都会有详细的usage的 这次算了 示意代码 实际要多不少 呵呵 #!/usr/bin/perl # # filter log # open(IN,"$ARGV[0]") || die "Couldn't open '$ARGV[0]': $!"; open(OUT,">>$ARGV[1]") || die "Couldn't open '$ARGV[1]': $!"; while(<IN>) { ($host, $longtime, $request) = /^(\S+) \[([^\]]+)\] \"([^\"]*)\"/; ($datetime, $zone) = split(/ /,$longtime,2); #($date, $time) = split(/:/,$datetime,2); #($hour, $minute, $second) = split (/:/,$time); $request =~ m#([A-Z_]*) ?([^ ]+) ?HTTP\/(\d.\d)?$#; $method=$1; $URL = $2; $proto=$3; print OUT $host." ".$datetime." ".$zone." ".$method." ".$URL." ".$proto."\n"; } close(IN); close(OUT); |
Posted by windtear at January 24, 2006 11:54 PM