[NTLUG:Discuss] Yet Another Scripting Request

Daniel Hauck daniel at yacg.com
Thu Aug 28 16:46:08 CDT 2008


You know, I'd probably do a lot more digging around on my own when it 
comes to advice and suggestions on how to write a script to accomplish 
one thing or another, but I think the global educational benefit is good 
for everyone here and for the archives of this mail list, so I will keep 
posting my scripting interests here.

Objective:

Write a script that will read through a directory and subdirectories and 
identify all files older than X days (let's just say 5 days if it helps) 
and delete them.

Overview of the problem:

I am setting up a "drop box" for file exchanges between a business and 
"contractors."  The mechanism we are using is already set up, but then 
we have the maintenance matter to consider.  Users will not voluntarily 
delete old files and it wouldn't be long before we had a lot of stuff on 
this server.  Since the purpose of this service is to allow a sub to 
upload or download files that are too large for email (10MB+) and not as 
a means of storage (and we know people would be tempted to use it that 
way... how many people store their lives in their email files?), I would 
like to set up a cron job that will at midnight delete all files that 
are older than a certain age in order to automatically clean that drop 
box area.

I think to begin with, a "find /path/to/root/directory" will generate a 
convenient recursive list of files to act on.  But after that, how do I 
query and compare file dates against the present date and stuff like 
that?  Or perhaps thereis even a better way to make it dig through 
subdirectories than feeding it the output of "find"?

I know this can't be a terribly original task and there will be a 
multitude of really good answers to go along with it.

Thanks for your participation.




More information about the Discuss mailing list