LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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

Reply
 
Search this Thread
Old 06-14-2004, 01:05 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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.
 
Old 06-14-2004, 01:25 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
What are you using for your logrotation? There should be an option to do it with that.
 
Old 06-14-2004, 01:29 PM   #3
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
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.
 
Old 06-14-2004, 02:10 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
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.
 
Old 06-14-2004, 02:25 PM   #5
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
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.
 
Old 06-14-2004, 09:05 PM   #6
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync files accessed under 30 days 0ddba11 Linux - General 3 11-03-2005 06:59 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 02:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 12:37 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 02:49 AM
Mandrake Auto Deletes my Programs?? bigbear_2345 Mandriva 7 12-05-2003 01:55 AM


All times are GMT -5. The time now is 11:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration