better way to clean out temp files

Bruce Raup brauplists at GMAIL.COM
Fri Sep 29 15:43:42 EDT 2006


Hi all,

I noticed that
http://mapserver.gis.umn.edu/docs/reference/systemmanage/referencemanual-all-pages
recommends a simple 'find' command to clean out the temporary
directory in a MapServer installation:

find /usr/local/www/docs/tmp -follow -name "*.gif" -exec rm {} \;

A problem with this is that image files can be deleted immediately
after they are created.  If you happen to be browsing such a MapServer
site at the moment the cron job runs, you might not see your image, or
at least you might not be able to press the 'back' button and see the
image you just viewed.  A better approach is the run a cron job more
frequently, and only delete files older than a certain time.  You
could do that, for site with very little traffic, by adding an option
to 'find':

find /usr/local/www/docs/tmp -follow -name "*.gif" -mtime +1 -exec rm {} \;

which would only delete files older than 1 day.

We needed to delete files sooner than that, so I wrote the attached
perl script to do the job.  I offer it as a potentially useful
addition to the above MapServer admin URL.  If you have any comments
on it, please let me know, at braup  'at'  nsidc.org.  It is designed
for Linux/UNIX (it runs the 'df' command in backticks), but this one
dependency could be taken out easily.  The reason I use 'rmtree' is
because our application creates temporary directories as well as temp
files.

Cheers,
Bruce Raup
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clean_tmp_area.pl
Type: application/x-perl
Size: 3901 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060929/3d924215/clean_tmp_area.bin


More information about the mapserver-users mailing list