script for dealing with temporary files

M S mseibel at GMAIL.COM
Fri Jun 16 18:41:39 EDT 2006


how about a cron job:
0 1 * * * /path/to/script

that runs a shell script:
rm -f /path/to/tmp/files/*;


On 6/16/06, Doyon, Jean-Francois <Jean-Francois.Doyon at ccrs.nrcan.gc.ca>
wrote:
>
> Good idea.
>
> Here's mine, written in Python.  It preserves the legend symbology but
> deletes other temporary images generated by mapserver:
>
> #!/home/atlas/web/bin/python
>
> # Directory where MapServer temporary files are created
>
> TMPDIR = '/dev/shm/atlas'
>
> # Time-To-Live (TTL) in minutes
>
> TTL = 5
>
> # Nothing to change below
>
> from glob import glob
> from os.path import getatime
> from os import unlink
> from time import time
> import re
>
> filelist = glob(TMPDIR + '/*.gif') + glob(TMPDIR + '/*.img.tmp')
> grace = TTL * 60
>
> for file in filelist:
>     try:
>         atime = getatime(file)
>         if atime < time() - grace and not
> re.match('^.*?_\d{5,6}_\d{10}_\d{1,2}_\d{1,2}_\d{1,2}_\d{1,2}\.gif$',
> file):
>             unlink(file)
>     except:
>         pass
>
> Cheers,
> J.F.
>
> -----Original Message-----
> From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU ] On
> Behalf Of Bruce Raup
> Sent: June 16, 2006 4:52 PM
> To: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: [UMN_MAPSERVER-USERS] script for dealing with temporary files
>
> I see in the mapserver documentation that a suggested way for removing
> temporary files that mapserver creates is a simple 'find' command:
>
> #!/bin/csh
> find /usr/local/www/docs/tmp -follow -name "*.gif" -exec rm {} \;
>
> A problem with this is that it even removes files that have just been
> created.  The -mtime option to find is a bit of help if you can wait a day
> to delete files, but we didn't have that option.  So I wrote a simple
> script
> in perl that allows you to specify a minimum age in minutes a file should
> have before it gets deleted.  I'm sure many other people have written such
> scripts, probably better ones than mine, but I thought I share mine since
> it's definitely better than the above 'find' command.  It's available at
> http://cires.colorado.edu/~braup/software/clean_tmp_area.pl<http://cires.colorado.edu/%7Ebraup/software/clean_tmp_area.pl>
>
> If you have any comments or suggestions for improvement, I'd be happy to
> hear about them.
>
> Cheers,
> Bruce
>
> --
> Bruce Raup
> http://cires.colorado.edu/~braup/ <http://cires.colorado.edu/%7Ebraup/>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060616/1a83b125/attachment.html


More information about the mapserver-users mailing list