简单分析apache日志的perl脚本

#!/usr/bin/perl
 
use Getopt::Std;
use warnings;
use strict;
 
sub load_log_file($) {
        my $log_filename = shift;
 
        open(FILE, "<", $log_filename) || die "Cannot open log file: $!\n";
        while(my $line = <FILE>) {
                $line =~ /^([0-9.]+)\s([\w.-]+)\s([\w.-]+)\s(\[[^\[\]]+\])\s"((?:[^"]|\")+)"\s(\d{3})\s(\d+|-)\s"((?:[^"]|\")+)"\s"((?:[^"]|\")+)"$/;   
 
                print "$1\n";
        }
 
        close FILE;
}
 
my %opts = ();
getopts("s:", \%opts);
if ($opts{'s'}) {
        print "LOADING LOGFILE $opts{'s'}";
        load_log_file($opts{'s'});
}
    原文作者:虓垚
    原文地址: https://segmentfault.com/a/1190000008663801
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞