1999-06-28-22:52:34 Shane Fisher:
Is there an elegant way to clean up the logfiles after awhile?
There are a great many ways.
A lot of procmailers use have fancy recipes to let them invoke commands using
procmail based on dates and times, as an ersatz cron. So far I've been able to
run real cron jobs everywhere I do procmail, and so I've evolved a logfile
rotator that suits my tastes:
#!/bin/sh
rotate(){
f="$1"
d=`dirname $f`
test -d $d || return
test -f $f || return
s=`ls -l $f|awk '{print $5}'`
test $s -gt 5242880 || return
test -f $f.6.gz && mv $f.6.gz $f.7.gz
test -f $f.5.gz && mv $f.5.gz $f.6.gz
test -f $f.4.gz && mv $f.4.gz $f.5.gz
test -f $f.3.gz && mv $f.3.gz $f.4.gz
test -f $f.2.gz && mv $f.2.gz $f.3.gz
test -f $f.1.gz && mv $f.1.gz $f.2.gz
test -f $f.0.gz && mv $f.0.gz $f.1.gz
mv $f $f.0
touch $f
gzip --best $f.0
}
rotate $HOME/.procmail/log
It's easy to rotate many different logfiles; just add additional invocations
of the rotate function to the bottom. The algorithm here is to let files grow
until they achieve some size threshhold (here 5MB), then rotate them and
compress the old one; and to keep some number (here 8) of archived compressed
logfiles.
-Bennett