[lug] Rotating Apache Log files

John Hernandez John.Hernandez at noaa.gov
Mon Jul 2 14:06:08 MDT 2001


The logrotate program is pretty slick.  Redhat RPM's generally use the logrotate facility by dropping config files into /etc/logrotate.d/ with rotation details.  The man page snippet below can give you a better idea of what it does.

NAME
       logrotate - rotates, compresses, and mails system logs
 
SYNOPSIS
       logrotate [-dv] [-f|--force] [-s|--state file] config_file+
 
DESCRIPTION
       logrotate  is  designed to ease administration of systems that generate large numbers of log
       files.  It allows automatic rotation, compression, removal, and mailing of log files.   Each
       log file may be handled daily, weekly, monthly, or when it grows too large.
 
       Normally,  logrotate is run as a daily cron job.  It will not modify a log multiple times in
       one day unless the criterium for that log is based on the log's size and logrotate is  being
       run multiple times each day, or unless the -f or -force option is used.

The Redhat Apache RPM creates /etc/logrotate.d/apache, which can be a good starting point, and you can get much fancier behavior by modifying this file.

-John

Greg Horne wrote:
> 
> Some of my sites generate many hits and the log file gets real big, manually
> deleting lines is tiring.  I'm trying to rotate my log files from various
> websites in this manner:
> 
> access_log ---------------> Todays log
> 07-02-01.access_log ------> Yesterdays
> 07-01-01.access_log ------> Day before that
> 
> Basically I will 'mv' access_log at the end of the day to a new file named
> according to the date, then restart apache thus creating access_log again
> all ready for the next day.  When I say put the date before the 'access_log'
> part i mean call the 'date' command and use it.  Like.....
> 
> -------rotate_logs---------
> 
> #!/bin/sh
> TODAY='date'
> WEBDIR="/home/www"
> 
> mv $WEBDIR/website/logs/access_log $WEBDIR/website/logs/$TODAY.access_log
> 
> ---------------------------
> 
> Thanks in advance,
> Greg
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

-- 

  - John Hernandez - Network Engineer - 303-497-6392 -
 |  National Oceanic and Atmospheric Administration   |
 |  Mailstop R/OM12. 325 Broadway, Boulder, CO 80305  |
  ----------------------------------------------------



More information about the LUG mailing list