* 正規表現によるApacheログ解析 [#zb60153f]
#!/usr/bin/perl
my $file = $ARGV[0];
open $fh, "<$file" or die "$!: $file";
while (my $line = <$fh>) {
chomp $line;
if ($line =~
m!^[\d\.]+?\s-\s-\s # SRC-IP - NAME - PASS
\[[^\]]+\]\s # [ DATE ]
"\w+?\s # HTTP REQUEST CMD
(/[^?]*?) # FILE PATH
[?|\S]*\s # QUERY STRING
[^"]*"\s # HTTP VERSION
(\d+?)\s # HTTP RESULT CODE
(\d+?)\s # FILE SIZE
".+?"\s # ?
"[^"]*?" # USER-AGENT
!x) {
$result_code = $2;
$file_size = $3;
if (($result_code == 200 || $result_code == 304) && $file_size <= 100) {
print "$1\n";
}
}
}
close $fh;