help with a script that deletes files more than X days old
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
help with a script that deletes files more than X days old
I want to delete my httpd access logs that are more than a week old. Any idea of a command or script that would do that? Something I could make a cron job & run once a day?
(just noticed my web server had 29 gigs of access logs over the last few months - a bit much )
FYI: my access log rotates daily, so this script/command needs to remove all files older than X date, not just clear out one file.
Check /etc/logrotate.conf... there should be something in there for apache logs that will tell it when to delete old ones... like if it says "rotate 7" then it will keep 7 days' worth of logs before it deletes the oldest one.
Originally posted by Donboy Check /etc/logrotate.conf... there should be something in there for apache logs that will tell it when to delete old ones... like if it says "rotate 7" then it will keep 7 days' worth of logs before it deletes the oldest one.
Notice I also added a line in there to send httpd a HUP signal. This is needed because when you erase the log files, apache need to be restarted.
This should all happen with your regular cron jobs. Take a look in /etc/cron.daily and see if there is a file in here that talks about logrotate. The contents of this file should execute logrotate and use logrotate.conf as the config file... therefore running the commands you are showing here.
Take a look at some of the other stuff in logrotate.conf and get an idea of what other parameters you can give to the apache logs. You can control a great deal of stuff using various commands.
Notice I also added a line in there to send httpd a HUP signal. This is needed because when you erase the log files, apache need to be restarted.
This should all happen with your regular cron jobs. Take a look in /etc/cron.daily and see if there is a file in here that talks about logrotate. The contents of this file should execute logrotate and use logrotate.conf as the config file... therefore running the commands you are showing here.
Take a look at some of the other stuff in logrotate.conf and get an idea of what other parameters you can give to the apache logs. You can control a great deal of stuff using various commands.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.