Logrotating single-issue files

Nicolas Mailhot Nicolas.Mailhot at laPoste.net
Mon Nov 10 14:39:02 UTC 2003


Le lun 10/11/2003 à 12:50, Jos Vos a écrit :
> On Mon, Nov 10, 2003 at 12:12:48PM +0100, Nicolas Mailhot wrote:
> 
> > 	The problem is of course once the files have been rotated once nothing
> > will recreate the original files so they'll be stuck in first rotation
> > forever (of course one might tell logrotate to create empty new files
> > after compression but that means filling the disk with empty files -
> > plus gziped empty files are *not* zero-sized anymore).
> 
> Well, yes, but at first sight creating new empty files seems to be
> the best solution.  Furthermore, IIRC you can define a shell script
> as "compresscmd" in your logrotate config, that could be like this
> (all untested, RTFM, I don't know the exact interface):
> 
> 	if [ -s $1 ]; then
> 		gzip $1
> 	else
> 		mv $1 $1.gz
> 	fi

Thank you for the idea, if got this awful hack to work now :

"/var/log/mydir" {
   rotate 4
   weekly
   nomissingok
   create
   ifempty
   compress
   compresscmd /usr/bin/rotatecomp
   compressext .bz2
   sharedscripts
   postrotate
      /usr/bin/rotateclean /var/log/mydir
   endscript
}

With /usr/bin/rotatecomp :
if ! [ "$#" -eq 2 -a -f "$2" ] ; then
    echo "$0: Usage $(basename $0) option file" >&2
    exit 1
fi
 
[ -s "$2" ] && bzip2 $1 $2 || mv $2 $2.bz2

And /usr/bin/rotateclean :
if ! [ "$#" -eq 1 -a -d "$1" ] ; then
    echo "$0: Usage $(basename $0) directory" >&2
    exit 1
fi
 
# Remove old logrotate leftovers
for file in $(find "$1" -type f | grep -E "\.[0-9]*\.bz2$" |\
              sed "s+^\(.*\)\.\([0-9]*\)\.bz2$+\1+g") ; do
   [ $(du -c $file* | tail -1 | sed "s+total$++g") -eq 0 ] && rm -f
$file*
done

Now this is all really ugly and I'd probably got as good a solution
writing a non-logrotate cron. Which proves logrotate is seriously
lacking when used in this (very simple and common) case:(.

Cheers,

-- 
Nicolas Mailhot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message num?riquement sign?e.
URL: <http://listman.redhat.com/archives/fedora-devel-list/attachments/20031110/fb0bba6e/attachment.sig>


More information about the fedora-devel-list mailing list