SUMMARY: Cron log rotation

From: Johan Hartzenberg <jhartzen_at_csc.com>
Date: Tue Aug 21 2001 - 06:53:08 EDT
Hi,

It seems I gave too little information in my original post.  I managed to
solve the problem by looking into the logchecker script and comparing the
one for Solaris 7 and the one for Solaris 2.6.

The difference is:

Solaris 2.6:
...
if [ $FILESIZE -ge $LIMIT ]
then
       mv $LOG $OLOG
       chgrp bin $OLOG
       >$LOG
       chmod 600 $LOG
       chgrp root $LOG
fi


Solaris 7:
...
if [ $FILESIZE -ge $LIMIT ]
then
        cp $LOG $OLOG
        chgrp bin $OLOG
        >$LOG
fi

At first I thought the Solaris 7 one was merely a little more efficient at
doing the same thing.
The variable LOG has got the value /var/cron/log
The variable OLOG has got teh value /var/cron/olog

However there's more to it than meets the eye:  The cron process remains
active when the "log rotation" turns the logs.  And in the first case, cron
continues to write to the renamed file... which made me realize cron has
got the file open the whole time, and we know a mv doesn't create a new
inode.  Indeed a truss on the cron process shows that it simply writes to
file descriptor #2 without opening or closing it each time.

The Solaris 7 script works because the inode is not changed, the data is
copied off to a new file (olog) and the existing file is then truncated at
0 bytes (by the command >$OLOG),whereas the same command in the SOlaris 2.6
script re-created the file with a different inode.

I am surprised nobody else have ever noticed this or logged a bug against
it! (Sunsolve reports ZERO documents against this script!)

I have added the following to the script to keep some more history:  Put
this right after the "then" statement.
        if [ -f ${OLOG}.0 ]; then
           cp ${OLOG}.0 ${OLOG}.1
        fi
        if [ -f ${OLOG} ]; then
           cp ${OLOG} ${OLOG}.0
        fi

Thanx to all who offered suggestions:
Michael Zinni
Sid Wilroy
Johan Sherman
Melinda Graham
David Harrington
Any other who's email is still winging to me.

  _Johan







                                                                                                                                  
                    Johan                                                                                                         
                    Hartzenberg          To:     sunmanagers@sunmanagers.org                                                      
                    Sent by:             cc:                                                                                      
                    Johannes J           Subject:     Cron log rotation                                                           
                    Hartzenberg                                                                                                   
                                                                                                                                  
                                                                                                                                  
                    20/08/2001                                                                                                    
                    02:23 PM                                                                                                      
                                                                                                                                  
                                                                                                                                  



Hi,

I notice it seems cron doesn't get its log files rotated.

Everything keeps on appending to /var/cron/olg and the file /var/cron/log
remains zero bytes for ever.

How is (should) this rotation be managed and where do I track down the
non-rotation.

Note - my cron jobs all run fine, the log files are just a little unwieldy.

P.S. This is happening on all the Solaris 2.6 systems, but Solaris 7
systems seems fine

Thanx,
  _Johan
Received on Tue Aug 21 11:53:08 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:25:02 EDT