From owner-freebsd-isp Mon Dec 6 13:42:44 1999 Delivered-To: freebsd-isp@freebsd.org Received: from roble.com (roble.com [206.40.34.50]) by hub.freebsd.org (Postfix) with ESMTP id CC86F14D37 for ; Mon, 6 Dec 1999 13:42:40 -0800 (PST) (envelope-from sendmail@roble.com) Received: from roble2.roble.com (roble2.roble.com [206.40.34.52]) by roble.com (Roble1b) with SMTP id NAA07362 for ; Mon, 6 Dec 1999 13:42:42 -0800 (PST) Date: Mon, 6 Dec 1999 13:42:37 -0800 (PST) From: Roger Marquis To: freebsd-isp@FreeBSD.ORG Subject: Re: Rotate httpd logs In-Reply-To: <3.0.5.32.19991206080611.0356bab0@ccsales.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-isp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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