Append to log file - Aix

This is a discussion on Append to log file - Aix ; Hi: can someone help me with the proper syntax. I know how to write in my script to append to a log file versusu overwriting it but does anyone k now how to clear that log file each day first ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Append to log file

  1. Append to log file

    Hi:
    can someone help me with the proper syntax.
    I know how to write in my script to append to a log file versusu
    overwriting it but does anyone k now how to clear that log file each
    day first then append to it thru out that day???
    thanks


  2. Re: Append to log file

    "capeme" writes:
    > Hi:
    > can someone help me with the proper syntax.
    > I know how to write in my script to append to a log file versusu
    > overwriting it but does anyone k now how to clear that log file each
    > day first then append to it thru out that day???
    > thanks


    One approach I've used happily in the past is to leverage syslog, and
    cut log entries to that facility using the logger command.

    Then you enjoy the economy of whatever syslog rolling policy you
    already have in place.

    Log rolling is tpyically done with a daily crontab entry that moves
    the current logfile out to another file compressed and archived by
    day, and then cat /dev/null > /working/logfile to keep the file handle
    fresh while emptying it out.

    Best Regards,
    --
    Todd H.
    http://www.toddh.net/

  3. Re: Append to log file

    Okay - so create a new cron entry that say at midnight do a :
    cat /dev/null > /tmp/logfileIusedthat day ?
    and that gets rid of that days logfile and the next time my script runs
    in the new day it will create new logfile for that day?


    Todd H. wrote:
    > "capeme" writes:
    > > Hi:
    > > can someone help me with the proper syntax.
    > > I know how to write in my script to append to a log file versusu
    > > overwriting it but does anyone k now how to clear that log file each
    > > day first then append to it thru out that day???
    > > thanks

    >
    > One approach I've used happily in the past is to leverage syslog, and
    > cut log entries to that facility using the logger command.
    >
    > Then you enjoy the economy of whatever syslog rolling policy you
    > already have in place.
    >
    > Log rolling is tpyically done with a daily crontab entry that moves
    > the current logfile out to another file compressed and archived by
    > day, and then cat /dev/null > /working/logfile to keep the file handle
    > fresh while emptying it out.
    >
    > Best Regards,
    > --
    > Todd H.
    > http://www.toddh.net/



  4. Re: Append to log file

    "capeme" writes:

    > Okay - so create a new cron entry that say at midnight do a :
    > cat /dev/null > /tmp/logfileIusedthat day ?


    That command will blank out /tmp/logfileIusedthat
    So you'll want to copy /tmp/logfileIusedthat to
    /tmp/thisdaysarchivedlogfile before that.

    > and that gets rid of that days logfile and the next time my script runs
    > in the new day it will create new logfile for that day?


    The command does not create a new logfile. It blanks the existing
    one.

    So, for instance, cron for every midnight

    cp /var/log/myniftyapp/messages /var/log/myniftyapp/messages-20061019.log
    gzip /var/log/myniftyapp/messages-20061019.log
    cat /dev/null > /var/log/myniftyapp/messages


    Add error checking preferably so you aren't blanking your log if the
    cp or gzip commands fail for whatever reason.

    --
    Todd H.
    http://www.toddh.net/

  5. Re: Append to log file

    Okay I will try that - thanks
    Todd H. wrote:
    > "capeme" writes:
    >
    > > Okay - so create a new cron entry that say at midnight do a :
    > > cat /dev/null > /tmp/logfileIusedthat day ?

    >
    > That command will blank out /tmp/logfileIusedthat
    > So you'll want to copy /tmp/logfileIusedthat to
    > /tmp/thisdaysarchivedlogfile before that.
    >
    > > and that gets rid of that days logfile and the next time my script runs
    > > in the new day it will create new logfile for that day?

    >
    > The command does not create a new logfile. It blanks the existing
    > one.
    >
    > So, for instance, cron for every midnight
    >
    > cp /var/log/myniftyapp/messages /var/log/myniftyapp/messages-20061019.log
    > gzip /var/log/myniftyapp/messages-20061019.log
    > cat /dev/null > /var/log/myniftyapp/messages
    >
    >
    > Add error checking preferably so you aren't blanking your log if the
    > cp or gzip commands fail for whatever reason.
    >
    > --
    > Todd H.
    > http://www.toddh.net/



  6. Re: Append to log file

    > filename <---- empty a file
    >> filename <-- append to a file


    0 0 * * * > filename 1>/dev/null 2>&1 <--- cron entry


  7. Re: Append to log file


    john_osell@hotmail.com a écrit :

    > > filename <---- empty a file
    > >> filename <-- append to a file

    >
    > 0 0 * * * > filename 1>/dev/null 2>&1 <--- cron entry

    If he uses your log via syslog, he may want to use logrotate inside
    syslog.conf..


+ Reply to Thread