[WBEL-users] [OT] Deleting files by date

Kirby Bohling kbohling@birddog.com
Tue, 20 Jul 2004 14:51:18 -0500


On Tue, Jul 20, 2004 at 03:41:16PM +0200, Andy Rabagliati wrote:
> On Tue, 20 Jul 2004, Jeff Maze wrote:
> 
> > Hello,
> > 	I was wondering if it's possible to delete files by a certain date
> > period (say over the last week).  Our secondary mail server has over 4000
> > messages that are over a week old, etc (even though sendmail is setup to
> > delete messages after 2.5 days in queue).  I'd like to delete these messages
> > that should have been deleted (leave 2.5 days worth of messages in the
> > /var/spool/mqueue directory).
> > 	Thanks..
> 
> In the days of Usenet News there was only one place to ask questions and
> get answers. The Balkanisation of this into a myriad of mailing lists is
> a step backwards.
> 
> Your question is best asked on a general Unix mailing list, your local Linux
> Users group, comp.os.linux.questions, or (better) a quick google.
> 
> This list is to address issues specific to whitebox vs RHEL, installs,
> packages, configuration.
> 
> To answer your question, "find" is your friend.
> 
> find /path/to/sendmail/messages +ctime 7 | xargs rm
> 
> Will probably do the job.
> 
> To do it regularly, "man crontab" and "man 5 crontab".

Personally, if I had to deal with it, I'd happily run tmpwatch to do
the job.  It's a tool meant to deal with this.  It should already be
in a crontab entry that runs, all you have to do is add the
directory you want watched.

Go to this:
/etc/cron.daily/tmpwatch

Add a line like this at the beginning:
/usr/sbin/tmpwatch 720 /path/to/sendmail/message

Furthermore if I was going to do it with find, I'd use the -exec
option, not the | "xargs rm"  some clever fellow could do something
like create a file named "-rf /", and you'll end up deleting the
whole machine.  Anytime I'm going to use "rm" with find, it's an
exec command, as I don't have to worry about any type of escaping or
shell commands.  There are lots of clever things like files with
spaces, or with newlines in then name that are a problem.  I've
found that -exec always works.  

I also think you have the syntax wrong, +ctime on my machine gives
an error.  This I believe is what you meant:

find /path/to/sendmail/messages -ctime +7 

Personally I'd do that with find like this:

find /path/to/messages -ctime +7 -exec rm {} \; -print

It's slower, but it's also safer.

Finally, I have no problems with people sending generic Linux
questions assuming two things:

1.  There isn't an obvious answer they can just look up (i.e. the
guys who ask, "What version of PHP does Whitebox have").

2.  They aren't flooding the list with questions.  

	It's a pretty low volume list, and I've found the answers sent
to the list to be inciteful.  I've been using Linux for 9 years, and
RedHat in particular for at least 7.  I've admin'ed lots of
machines, and I know that William Hooper periodically sends a
message that I'm happy to learn what his answer is.  I know that
Johnny Hughes Jr. sends things that don't fit your version of what
this list should be for.  However, I think the list is better off
for his posts.

	I try and answer my fair share of questions, and would like to
think I'm reasonably smart when it comes to Linux.  So I guess I'd
hate to see the questions get discouraged.  However, I don't run the
list, so my opinion is just that, my opinion.  

	Thanks,
		Kirby



> 
> Cheers,    Andy!
> _______________________________________________
> Whitebox-users mailing list
> Whitebox-users@beau.org
> http://beau.org/mailman/listinfo/whitebox-users
>