Article View: best.general
Article #294Re: More on web log files
From: Joe Smith
Date: Mon, 26 Nov 2001 10:15
Date: Mon, 26 Nov 2001 10:15
112 lines
4942 bytes
4942 bytes
In article <9trjbb$n4q$1@nntp1.ba.best.com>,
Patty Winter <pwinter@best.com> wrote:
>I just noticed the problems everyone has been talking about with
>the logs on the new web servers. In searching the Verio knowledge
>base for information about the log format, I found an entry saying
>that the referrer and user-agent info could be added by request.
>So I sent a note to Verio Support asking for them, and just got
>a reply that they're only available to users of the VPS system.
>Those of us on the low-cost accounts all share the same config
>file that doesn't include that information. :-(
I have a $30/month account, and they enabled it for me on request.
>Has anyone found a way to split those big access logs into
>separate days?
#!/usr/bin/perl
# Name: ~/www/bin/rotate_logs Author: part of iServer from Verio
# Purpose: Rotates the Apache logs and compresses them. Optional logresolve.
#
# 20000403 PJL - creation of script
# 20010807 PJL - modified for use with Confluence and streamlined a bit
# 20010807 PJL - Fixed a bug not deleting the old compressed logs
# 20010809 PJL - Mainly matched Confluence's control panel format
#
# Modifications done by Joe.Smith@inwap.com
# 20011031 JMS - Change naming convention to YYYY/MMDD-acc and YYYY/MMDD-err.
# 20011101 JMS - Use `logresolve` on the files specified on the command line.
# Use "crontab -e" and change to the entry that runs this script to:
# TZ=PST8PDT
# 00 16 * * * www/bin/rotate_logs access_log # Daily, logresolve
use POSIX qw(strftime);
use File::Copy;
use strict;
#my @logs = ('access_log','error_log','script.error_log','controlpanel.log');
my @logs = qw(access_log error_log referer_log); # Keep other 2 as is
my $CURLOG_DIR = "$ENV{'HOME'}/www/logs";
my $GZIP = "/usr/bin/gzip";
my $LOGRESOLVE = "/usr/local/apache/bin/logresolve";
# Get the date for the filename extension
# First strftime() returns "Thu-Nov-01-2001:16:10:26"
#my $curstr = strftime("%a-%b-%d-%Y:%H:%M:%S",localtime(time));
my @now = localtime(time);
# $wday = strftime("%a", @now);
my $yyyy = strftime("%Y", @now);
my $mmdd = strftime("%m%d",@now);
my $dst_dir = "$CURLOG_DIR/$yyyy";
mkdir $dst_dir,0755 unless -d $dst_dir;
# Make two passes over the list of log files
# 1st pass: Quickly copy and truncate each log
my %logs;
foreach my $log (@logs) {
my $src = "$CURLOG_DIR/$log";
my $dst = "$dst_dir/$mmdd-" . substr($log,0,3);
if (-s $src) {
$logs{$log} = $dst;
copy($src,$dst) || warn "copy($src,$dst): $!\n";
copy("/dev/null",$src) || warn "copy(null,$src): $!\n";
}
}
# If 'access_log' is specified on the command line, convert numeric IP
# addresses in it to host names. It can take 60 minutes to do 40000 lines.
lookup_dns($_) foreach @ARGV; # Use "www/bin/rotate_logs access_log"
# 2nd pass: Compress the logs.
die "gzip is not available!" unless -x $GZIP;
compress_log($_) for values %logs;
exit(0);
#####################################################################
sub do_warn (@) {
warn @_;
system qw(quota -v); # Error may be due to disk quota exceeded
system qw(ls -alt); # Show size of newest files
}
sub compress_log {
my $path = shift;
my $output = "$path.gz";
return warn "$output already exists" if -f $output;
system($GZIP, "--best", $path);
do_warn "'$GZIP $path' returned $?" if $?;
}
sub lookup_dns {
my $file = shift; # Original file name
my $log = $logs{$file}; # Where it got copied to
if (-s $log) {
my $tmp = "$log.$$";
my $mtime = (stat $log)[9]; # Preserve modification time
system "$LOGRESOLVE <$log >$tmp";
do_warn "$LOGRESOLVE returned $?" if $?;
move($tmp,$log) || warn "move($tmp,$log): $!\n";
utime($mtime,$mtime,$log) || warn "utime($log): $!\n";
} else {
warn "Did not run $LOGRESOLVE on $file ($log)\n";
}
}
1;
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
Technical Details
Message-ID:
<9tt4or$ou0$1@nntp1.ba.best.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news2.best.com!nntp1.ba.best.com!inwapReferences:
<9trjbb$n4q$1@nntp1.ba.best.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f9f6d,35114d4ad3ed1d80 X-Google-Attributes: gidf9f6d,public X-Google-Thread: fdc27,35114d4ad3ed1d80 X-Google-Attributes: gidfdc27,public X-Google-ArrivalTime: 2001-11-26 02:16:08 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news2.best.com!nntp1.ba.best.com!inwap From: inwap@best.com (Joe Smith) Newsgroups: best.general,best.migration Subject: Re: More on web log files Date: Mon, 26 Nov 2001 10:15:55 +0000 (UTC) Organization: Chez Inwap Lines: 112 Distribution: best Message-ID: <9tt4or$ou0$1@nntp1.ba.best.com> References: <9trjbb$n4q$1@nntp1.ba.best.com> NNTP-Posting-Host: shell3.ba.best.com X-Trace: nntp1.ba.best.com 1006769755 25536 206.184.139.134 (26 Nov 2001 10:15:55 GMT) X-Complaints-To: abuse@best.com NNTP-Posting-Date: Mon, 26 Nov 2001 10:15:55 +0000 (UTC)