-
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?
-
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.old
apachectl graceful
sleep 600
gzip access_log.old error_log.old
-
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.