Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Chicago, Illinois

    Dealing with log files

    I have apache rotate the logs daily and keep them in the users home directory in /logs/, however; these logs pile up over time and I need to delete them by hand. What is the best way to automate deletion of these log files? For example, i'd like to delete the logs after 7 days of logging. Can I do this with newsystemlog or somethign similar? Or do I need a shell script?

  2. #2
    Join Date
    Jan 2007
    As far as I know you'll have to restart the server to delete the old log files and create new ones. This shouldn't be an issue as it's a fairly quick process and something you can afford to do every 7 days.

    You can compress and rotate log files using a command similar to...

    PHP Code:
    mv access_log access_log.old
           mv error_log error_log
           apachectl graceful
           sleep 600
           gzip access_log
    .old error_log.old 
    <<Please see rules for signature setup>>

  3. #3
    Sounds like you already have a cron script in place which rotates apache's logs and places them in /logs/ and if that's the case then simply add a line to that cron script which removes the last logs. The best way to do everything which must be done regularly is to do it by placing a script in /etc/cron.daily/ or /etc/cron.weekly/ .. never do anything manually which could be done for you by a script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts