Cleaning the /tmp directory

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Mon May 23 10:43:20 PDT 2005


On Linux I use:

    find /data/mdata/tmp -type f -mmin +20 -exec rm -f {} \;

from a root crontab entry.

If you have perl running on your windows server, here is a script that
will remove all the tmp files that are older the 20 min. This was
generated by find2perl and then modified. Use at your own risk.

-Steve W.

#! /usr/bin/perl -w
     eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
         if 0; #$running_under_some_shell

use strict;
use File::Find ();

#################################### config here #########
my $older = 20/1440;     # 20 minutes / 1440 minutes/day
my $scan_dir = '/data/mdata/tmp';
##########################################################


# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;



# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, $scan_dir);
exit;


sub wanted {
     my ($dev,$ino,$mode,$nlink,$uid,$gid);

     (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
     -f _ &&
     (-M _ > $older) &&
     unlink($_);
}


Lester Caine wrote:
> John Kim wrote:
>
>>  > from : http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PHPMapScriptRH72
>>  > there is :
>>  > Setup MapServer IMAGEDIR and cleanup script
>>  > ...
>>
>> Any tips on how you'd do this in Windows?
>
>
> I just run a scheduled task which is a batch file that deletes all the
> files. It runs a midnight, so anybody working at that time might see a
> problem.
> I really must get round to writing a program that just deletes anything
> over x hours old so that it is not so violent with files that have just
> been created ;)
>
> --
> Lester Caine
> -----------------------------
> L.S.Caine Electronic Services
>



More information about the MapServer-users mailing list