proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« [公告] 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);
本blog WWW

Posted by windtear at January 24, 2006 11:54 PM

本站使用中的任何问题,请与 windtear @ windtear.net 联系
Copyright© 1999-2024 Windtear. All rights reserved.