Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-14-2004, 01:05 PM
|
#1
|
|
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334
Rep:
|
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.
Thanks
Last edited by BrianK; 06-14-2004 at 01:09 PM.
|
|
|
|
06-14-2004, 01:25 PM
|
#2
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
What are you using for your logrotation? There should be an option to do it with that.
|
|
|
|
06-14-2004, 01:29 PM
|
#3
|
|
Member
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736
Rep:
|
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.
|
|
|
|
06-14-2004, 02:10 PM
|
#4
|
|
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334
Original Poster
Rep:
|
Quote:
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.
|
Thanks - I configured it as such (just now):
Code:
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 7
nomail
postrotate
endscript
}
Does this seem resonable?
Do I need to execute anything to make this go or does it check it every time the log rotates?
Thanks again.
|
|
|
|
06-14-2004, 02:25 PM
|
#5
|
|
Member
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736
Rep:
|
You can use wildcards... so maybe you can rewrite it like...
Code:
/var/log/httpd/*.log {
rotate 7
nomail
postrotate
endscript
/usr/bin/killall -HUP httpd
}
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.
|
|
|
|
06-14-2004, 09:05 PM
|
#6
|
|
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334
Original Poster
Rep:
|
Quote:
Originally posted by Donboy
You can use wildcards... so maybe you can rewrite it like...
Code:
/var/log/httpd/*.log {
rotate 7
nomail
postrotate
endscript
/usr/bin/killall -HUP httpd
}
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.
|
Excellent. Thanks for the help. 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:44 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|