#用法传入日志文件
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $CurrTime = (split / /,time2iso(time()))[0];
my %log;
if ( $#ARGV < 1 ){
print "please input your date!
";
exit(-1);
}
$date= $ARGV[0];
$ip_addr = $ARGV[1];
@file = glob "/data/backup_log/othrun/mbankapp/$ip_addr/$date/logs.log$date*";
foreach $file (@file){
# print "------file is $file-----------
";
my %log;
open (LOG ,"<","$file");
while (<LOG>) {
chomp;
##正则条件匹配
if ($_ =~ /X-Forwarded-For====(d{1,3}.d{1,3}.d{1,3}.d{1,3})/){
#print "$1 is $1
";
$var= $1;
$log{$var}++;
}
}
};
if (-f "mbank$ip_addr-$date.log"){unlink "mbank$ip_addr-$date.log"};
while(my($ip, $times) = each %log) {
print "$ip $times
";
open (B ,">>mbank$ip_addr-$date.log");
print B ("$ip $times
");
}
$count = `wc -l mbank$ip_addr-$date.log`;
print "访问总数为:$count
";