[Gllug] Apache log files

Peter Corlett abuse at cabal.org.uk
Wed Apr 8 15:02:18 UTC 2009


On Wed, Apr 08, 2009 at 03:28:12PM +0100, william pink wrote:
[...]
> That looks great but I am using the timestamps in the actual logfile
> (which from what I can work out that script uses the date in the log file
> name but that maybe a error of judgment?

It *is* using the timestamps from the file. This code:

>>  my($day, $month, $year) = (m~\[(..)/(...)/(....):~);
>>  die "Regex match failed" unless defined $1; # regex sanity check
>>  my $path = "$year-$month-$day.access.log";

... does a regex match on the incoming line to find the day, month and year,
bails if there wasn't a match (which points to a corrupt file or duff
regex), and then generates an output filename from that.

The unless() bit just opens a new file when the day rolls over, so it's not
doing an open() per line. And, on reflection, there's a bug in the script
where it clobbers rather than appends to files; this causes a problem if
your logfiles aren't in chronological order. Change '>' to '>>' in the open
statement to fix that.

> I have just ordered Perl for system administration also as I think Perl is
> another thing I should really learn.

It's quite a fine book, although you might also find Learning Perl to be of
use.

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list