#!/usr/bin/perl
#write by
litao
#date 2013-2-21
#for filter php php-fpm log between two times
use Date::Manip;
if ($#ARGV != 1 ) {
print "usage: php-fpm.pl
start-time end-time\n";
print
"date format like:\n";
print "21-Feb-2013
00:00:00";
exit;
}
#shift date to
date variable
my $datestr1=$ARGV[0];
my $datestr2=$ARGV[1];
my $date1 = new
Date::Manip::Date;
my $date2 = new
Date::Manip::Date;
$date1->parse($datestr1);
$date2->parse($datestr2);
open(PHPLOG,
"php-fpm.log");
open(PLOT,">>output") || die ("This file will not
open");
while (<PHPLOG>) {
my $line =
$_;
chomp($line);
(my $subtimestr) = $line =~
/\[(.*\d+:\d+:\d+)\]/;
my $subtime1 =
$date1->new_date;
$subtime1->parse($subtimestr);
my $result1
= $date1->cmp($subtime1);
my $subtime2 =
$date2->new_date;
$subtime2->parse($subtimestr);
my $result2
= $date2->cmp($subtime2);
next if ($result1 == 1);
last if
($result2 == -1);
print PLOT "$line\n" if ( $result1 < 1 and $result2
> -1 );
}
close(<PHPLOG);
close(<PLOT);
2013年3月31日星期日
perl 取时间段php fpm log
订阅:
博文评论 (Atom)
订阅:
博文评论 (Atom)
没有评论:
发表评论