[WEB4LIB] Re: log file rotation

Thomas Dowling tdowling at ohiolink.edu
Thu Jan 10 12:56:14 EST 2002


At 11:38 AM 1/10/2002, Darryl Friesen wrote:
> > What I would like to do is to have a new log
> > file starting at midnight of each day and keep the old log files
> > indefinitely for right now, until we figure out how long we want to keep
> > them, storage methods, etc.
>
>There's a number of ways.  You could have a cron job that runs each night
>which does something like this:
>
>     #!/bin/sh
>     cd /usr/local/apache/logs
>     mv access_log access.yyyy_dd_mm.log
>     mv error_log  error.yyyy_dd_mm.log
>     /usr/local/apache/bin/apacectl graceful
>
>(where yyyy, mm and dd are the year month and day for the previous day) or
>you could use the rotatelogs application that comes with Apache.  It's use
>is covered in a few places on the Apache site, including
>http://httpd.apache.org/docs/programs/rotatelogs.html

Or alternatively:

   #!/usr/bin/ksh

   today=`/usr/bin/date +"%Y%m%d"`
   # That will get the date automatically.

   cd /wherever/you/keep/logs
   mv access_log /where/you/archive/old_logs/access.$today.log
   mv error_log /where/you/archive/old_logs/error.$today.log
   /web/apache/bin/apachectl graceful

Or 'date +"%Y%m" if you rotate monthly, "%Y%W" if you do it weekly.  If 
you're bothered by having today's date on yesterday's log, just cron it to 
run at 11:59pm.


I'm old enough that my scripts still find and "kill -HUP" the Apache 
proccess ID.  Apache has just gotten so user friendly over the 
years.  Who'da thunk it would ever have a "graceful" option?  :->


Thomas Dowling
OhioLINK - Ohio Library and Information Network
tdowling at ohiolink.edu



More information about the Web4lib mailing list