perl分析apache日誌

虓垚發表於2019-02-16
#!/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: $!
";
        while(my $line = <FILE>) {
                $line =~ /^([0-9.]+)s([w.-]+)s([w.-]+)s([[^[]]+])s"((?:[^"]|")+)"s(d{3})s(d+|-)s"((?:[^"]|")+)"s"((?:[^"]|")+)"$/;   
 
                print "$1
";
        }
 
        close FILE;
}
 
my %opts = ();
getopts("s:", \%opts);
if ($opts{`s`}) {
        print "LOADING LOGFILE $opts{`s`}";
        load_log_file($opts{`s`});
}

相關文章