On Tue, May 11, 2004 at 11:04:21PM -0400, JJB wrote:
> In an csh script I want to issue newsyslog /var/log/security. I need
> feedback from the newsyslog command in the form of an script
> testable return code / exit code so I can determine if the specified
> log met the rotate trigger for that file as defined in the
> newsyslog.conf file and the file was rotated or not.  I have tested
> and know that  newsyslog /var/log/security does check the
> newsyslog.config for an entry of /var/log/security and checks the
> size/time/date trigger to determine if file needs rotating.

Is there any particular reason you've decided to write your script in
*csh*?  That is, I'm afraid, in very poor taste.  For a full
exposition of csh programming is considered harmful, see:


Keep csh(1) for what it does best -- being an interactive shell -- and
do all your shell programming using Bourne shell.  This may seem like
arbitrary and irrelevant advice right now, but trust me: keep
programming in csh and you're going to regret it. Maybe not today,
maybe not tomorrow, but some and for the rest fo your life.

> So my question boils down to does the newsyslog command  issue an
> return code I can check in an script to see if the log was rotated
> or not? If so what would the csh script command look like to perform
> the test?

Now, your question: unfortunately newsyslog(1) does not indicate any
sort of success or failure via it's return code.  Infact, unless you
give it a nonsensical command line triggering the usage() message, it
will always return a successful status.

Your next alternative is to test and see if the logfile is large
enough to trigger newsyslog.  In order to get the size of the file in
bytes use:

    filesize=`stat -f %z filename`

Then to test that the filesize is greater than 100k (which is the
typical size used to trigger logfile rotation in newsyslog.conf):

    if $(( $filesize > 100 * 1024 )) ; then
        # Stuff to do if the file is bigger

Alternative approaches would be to look at the modification times on
the *rotated* log files -- obviously the modification time on an
active log file is constantly changing.  Again the stat(1) command can
get you that information:

    stat -f %m filename

which gets you the time expressed as the number of seconds since the
epoch (00:00h, 1st January 1970 UTC).  Hint: to get the current
time+date in the same format use:

    date +%s



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to