Date: Mon, 6 Dec 1999 13:42:37 -0800 (PST) From: Roger Marquis <marquis@roble.com> To: freebsd-isp@FreeBSD.ORG Subject: Re: Rotate httpd logs Message-ID: <Pine.GSO.3.96.991206131014.12383B-100000@roble2.roble.com> In-Reply-To: <3.0.5.32.19991206080611.0356bab0@ccsales.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 6 Dec 1999, Randy A. Katz wrote:
> Just trying to get a clue about how I should rotate httpd logs, how
> frequently, and whether to use rotatelogs (included in Apache) or something
> else. If any of you could share your methods I'd appreciate it.
Unlike syslogd Apache httpd keeps the logfile open as long as the
daemon's running. This eliminates the need to rotate logfiles larger
than a certain size, unless you have a very small log partition.
For most sites you can rotate the logs monthly. We do that here and
then run reports on the previous month.
Try this in your /etc/periodic/monthly or /etc/crontab:
/bin/sh -
# Assume all logs are in the $LOGDIR
LOGDIR=/var/log
#
# rotate OLD logs, keep 4 {month}'s worth in $LOGDIR/OLD
# (in addition to the compressed archives created previously)
#
cd $LOGDIR
for file in `ls OLD/*messages*.2` ; do
cp $file "` echo $file|sed 's/.2$/.3/' `"
done
for file in `ls OLD/*messages*.1` ; do
cp $file "` echo $file|sed 's/.1$/.2/' `"
done
for file in `ls OLD/*messages*.0` ; do
cp $file "` echo $file|sed 's/.0$/.1/' `"
done
#
# archive this {month}'s and # clean up for next {month}
#
cd $LOGDIR
for file in `ls *messages` ; do
## combine up to 10 previously rotated logs
for i in 9 8 7 6 5 4 3 2 1 0 ; do
if [ -s ${file}.${i} ]; then
cat ${file}.${i} >> ${file}.tmp
fi
rm -f ${file}.${i}
done
if [ -s ${file} ]; then
cat ${file} >> ${file}.tmp
# null out open logfiles
cp /dev/null ${file}
fi
if [ -s ${file}.tmp ]; then
# archive unless empty
cp ${file}.tmp OLD/${file}.0
fi
rm -f ${file}.tmp
ls -ltgF OLD/${file}.0 ${file}
done
chown -R 0.0 /var/log/OLD
chown -R 0.0 /var/log/*messages*
chown nobody.nogroup /var/log/http*messages 2>&1 >/dev/null
chmod 750 /var/log/OLD
chmod 640 /var/log/OLD/*
--
Roger Marquis
Roble Systems Consulting
http://www.roble.com/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.3.96.991206131014.12383B-100000>
