Re: newsyslog command in an script

From: Matthew Seaman (m.seaman_at_infracaninophile.co.uk)
Date: 05/12/04

  • Next message: Rob: "CUPS: ipp connection to printer times out !?!"
    Date: Wed, 12 May 2004 18:19:00 +0100
    To: JJB <Barbish3@adelphia.net>
    
    
    

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

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


    • application/pgp-signature attachment: stored

  • Next message: Rob: "CUPS: ipp connection to printer times out !?!"

    Relevant Pages

    • SUMMARY : which command comes back with no match then result
      ... Darren Dunham, Jeff Woolsey, Brad Morrison, and Chris Buesgens ... /usr/bin/which is a 'csh' script. ... Since 'which' is a shell script, ... Run a truss command on the which command. ...
      (SunManagers)
    • Re: problem with sed command and csh
      ... i'm working on FreeBSD 6.2 and csh shell. ... With a sh script, i ... trying to execute this command: ... that is not used as a separator for the s command. ...
      (freebsd-questions)
    • Re: Startup errors....su:/bin/csh Perm denied..
      ... There are at least two things going on and one at least has nothing to do with mysql. ... AFAIK nothing in the startup scripts uses csh. ... You think the mysql start script is attempting to create a file in /var/spool/clientmqueue? ... Run the script one command at a time by doing the following: ...
      (freebsd-questions)
    • Re: Why does this work in terminal only !?
      ... in a terminal the file is moved to ~/.Trash with its name intact. ... if I do the same thing via an add-on command option - right click ... that nothing is passed to the script. ... You can pass the file, you clicked on to trigger the action, using the ...
      (alt.os.linux)
    • Re: shell issues
      ... > for: Command not found. ... Second, csh is the wrong interpreter for your script, as ...
      (comp.unix.admin)