Summary.Net Archives
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Summary-Talk] script to gzip apache access logs on OSXS?



Thanks for the pointers, Jason,

I, too, was surprised that we couldn't find anything similar online. I
would think lots of people would want this. Is it normal for people to
be discarding their logs files weekly or monthly? I've never
understood that.

At any rate, this is what we came up with. It seems to work nicely,
leaving the current, active log file alone:



#!/bin/bash

# script to find apache logs older than X days and gzip them

# path to search
BEGINPATH=/path/to/apache/logs/
# grep pattern to search for
FILENAMEPATTERN='access\_log\.[0-9]*[^\.gzip]$'
# number of days since the file was modified, so we don't gzip active 
log file
NUMDAYS=+8

# here goes
for LOGFILE in `find $BEGINPATH -mtime $NUMDAYS | grep $FILENAMEPATTERN`
do
         # what you want the script to do
         gzip $LOGFILE
done




On 09/06/06, Jason Linhart <jason@xxxxxxxxxxx> wrote:
> Apple uses rotatelogs, which doesn't provide for log file compression.
>
> Writing a script to do compression would be a little tricky, since you
> need to be careful not to compress the currently active log file, and
> all of the ways I can think of to figure that out require some
> relatively advanced scripting tricks.
>
> I use logrotate instead of rotatelogs, which does provide for
> compression. Logrotate also keeps only the most recent N log files,
> instead of all of them, which I like and it has less CPU overhead.
> Unfortunately it does not come with OS X and getting it to work with
> Apache tends to require a through understanding of Apache configuration
> files and avoiding Apple's web site administration tool.
>
> Another approach would be to use httplog instead of rotatelogs,
> <http://freshmeat.net/projects/httplog/>. Again some technical knowledge
> would be required to glue things together, and httplog hasn't been
> updated for some time.
>
> I am rather surprised that there isn't a more polished solution available.
>
> Jason
>
>
> Mac OS X Server Administrator wrote:
> >
> > Our Apache server creates new log files every seven days, and never
> > deletes them (which is good), but since we keep all of our log files,
> > we'd like it to be gzipping them, too.
> >
> > I'm assuming this is something many people are doing, too, but I can't
> > find any shell scripts that do this (google, macosxhints, afp548,
> > etc.).
> >
> > Anyone like to share? (Tiger and Panther Servers, bash and tcsh,
> > respectively).
>
> --
> Jason@xxxxxxxxxxx
> --
> Dr. Seuss books . . . can be read and enjoyed on several levels. For
> example, 'One Fish Two Fish, Red Fish Blue Fish' can be deconstructed
> as a searing indictment of the narrow-minded binary counting system.
>    -- Peter van der Linden, Expert C Programming, Deep C Secrets
-------------
Go to <http://summary.net/list.html> to update subscription info.