#!/usr/local/bin/perl # # generic /tmp cleaner # matches fielname patter (if you wish) # and "older than" criteria # $comparefile = '/tmp/timestmp'; $dirname = '/tmp'; # remove files more than 40000 seconds old... $interval = 40000; #pattern to match in files $pattern = "mutt"; #set our comparison time (now) system ("touch $comparefile"); #find the times on the comparison file ($compread, $compwrite) = (stat($comparefile))[8,9]; #all files before $killtime will be rm'ed $killtime = $compwrite - $interval; #now process all files in /tmp opendir(DIR,$dirname) or die "can't opendir $dirname: $!"; #loop thru files now: while (defined($file = readdir(DIR))) { if ($file =~ $pattern) { $file = '/tmp/' . $file; ($fileread, $filewrite) = (stat($file))[8,9]; if ($filewrite < $killtime) { unlink $file; } } } closedir(DIR); exit;