Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 May 2004 18:19:00 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        JJB <Barbish3@adelphia.net>
Cc:        "freebsd-questions@FreeBSD. ORG" <freebsd-questions@freebsd.org>
Subject:   Re: newsyslog command in an script
Message-ID:  <20040512171859.GE28587@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <MIEPLLIBMLEEABPDBIEGIENMFNAA.Barbish3@adelphia.net>
References:  <MIEPLLIBMLEEABPDBIEGIENMFNAA.Barbish3@adelphia.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--G6nVm6DDWH/FONJq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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:

    http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

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=3D`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
        ...
    fi

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

	Cheers,

	Matthew

--=20
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

--G6nVm6DDWH/FONJq
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAolyDiD657aJF7eIRAszPAJ0U5ovinbTRjLCWGLnOt4+03BTj8gCcCi0U
wiIuof0ctgC3ig5svyZYlbw=
=cCQe
-----END PGP SIGNATURE-----

--G6nVm6DDWH/FONJq--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040512171859.GE28587>