#!/usr/bin/perl
###########################################################
###########################################################
#
# Author(s): Lee Chia Ling
# Date Created: 19 Oct 1999
#
# Filter ca access_log and error_log and ssl_engine_log
# By default, show yesterday's
#
###########################################################
###########################################################
## print "ARGV[0] = ".$ARGV[0]."\n";
$days_argument = 1;
$ARGV[0] && ($days_argument = $ARGV[0]);
## print "Displaying the logs of ".$days_argument." days ago.\n";
$yesterday = localtime(time-$days_argument*24*60*60);
# print "yesterday = ".$yesterday."\n";
# $yesterday_month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[(localtime(time-24*60*60))[4]];
# $yesterday_day = (localtime(time-24*60*60))[3];
($yesterday_day_of_week, $yesterday_month, $yesterday_day) = split / +/, $yesterday;
# print "yesterday_month = ".$yesterday_month."\n";
# print "yesterday_day = ".$yesterday_day."\n";
$long_yesterday_day = (length($yesterday_day) == 1) ? '0'.$yesterday_day : $yesterday_day;
print "---------------------------------------------\n";
print "------/usr/local/apache/logs/access_log------\n";
print "---------------------------------------------\n";
open FILE,"/usr/local/apache/logs/access_log";
while () {
# print "Original Line is = ".$_;
($throwaway1, $day, $month, $throwaway2) = split /\[(\d{2})\/(\w{3})\//, $_;
# print "day is = ".$day."\n";
# print "month is = ".$month."\n";
if (($month eq $yesterday_month) &&
($day eq $long_yesterday_day)) {
print $_;
}
}
close FILE;
print "--------------------------------------------\n";
print "------/usr/local/apache/logs/error_log------\n";
print "--------------------------------------------\n";
open FILE,"/usr/local/apache/logs/error_log";
while () {
# print "Original Line is = ".$_;
($throwaway1, $month, $day, $throwaway2) = split /\[\w{3} (\w{3}) +(\d+) /, $_;
## print "day is = ".$day."\n";
## print "month is = ".$month."\n";
if (($month eq $yesterday_month) &&
($day eq $yesterday_day)) {
print $_;
}
}
close FILE;
print "-------------------------------------------------\n";
print "------/usr/local/apache/logs/ssl_engine_log------\n";
print "-------------------------------------------------\n";
open FILE,"/usr/local/apache/logs/ssl_engine_log";
while () {
# print "Original Line is = ".$_;
($throwaway1, $day, $month, $throwaway2) = split /\[(\d{2})\/(\w{3})\//, $_;
# print "day is = ".$day."\n";
# print "month is = ".$month."\n";
if (($month eq $yesterday_month) &&
($day eq $long_yesterday_day)) {
print $_;
}
}
close FILE;