trimming log files that are always open

From: Spurgeon, John P (john.p.spurgeon@intel.com)
Date: Fri Jan 24 2003 - 18:39:09 EST


We're using the following algorithm to trim various log files on a Solaris 7
system:

if [ "$SIZE" -ge "$LIMIT" ]
then
        echo "Rotating file $FILE. Size is $SIZE bytes. Limit is $LIMIT
bytes."
        i=`expr $BACKUPS - 1`
        while [ "$i" -gt 0 ]
        do
                j=`expr $i - 1`
                test -f $DEST.$j && mv -f $DEST.$j $DEST.$i
                i=$j
        done
        if [ "$BACKUPS" -gt 0 ]
        then
                test -f $DEST.0 && rm -f $DEST.0
                cp -p $FILE $DEST.0
        fi
> $FILE
fi

The problem is that a program appears to keep a particular log file open all
the time. After the file is "cleared" by the command "> $FILE", the "ls"
command temporarily reports that the new file size is zero, but as soon as
the program starts writing to the file again, the size jumps back up to its
previous value. Interestingly, when you view the file using vi, you only see
the new lines that were written after the contents were supposedly cleared.
But the file size just keeps growing.

I can solve the problem by stopping the program that has the file open,
rotating the log file, and then restarting the program, but I'd rather find
some way to trim the log file without interrupting the program or sending it
a hang up signal. Is this possible? How?

Regards,
John Spurgeon
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:25:43 EDT