#!/usr/local/bin/perl # # Name :rmads # Author :Kang SoonLai # Date :Wed Apr 09 1997, 01:52:01 PM # Path :/users/skang/public_html/banner/rmads # Email :skang@ittc.ukans.edu # WWW :http://www.tisl.ukans.edu/~skang # # rm files that are more than one hour old. # should submit it to the crontab, eg: # crontab -l # add this line when the editor comes up, # # 30 2 * * * /users/skang/public_html/banner/rmads # # this is an example of mine. it cleans up the dir every day at 2:30am. # you have to change the path above though. # # ############################################################################### $dir = "/users/skang/public_html/banner/tmp"; $num=0; #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); #$date=sprintf("%02d%02d%02d",$year,$mon+1,$mday); opendir(DIR,$dir) || die "Can't open dir: $!\n"; chdir($dir); readdir(DIR); readdir(DIR); while ($file=readdir(DIR)) { ($atime,$mtime,$ctime)=(stat($file))[8..10]; #print "$file : $atime, $mtime, $ctime\n"; # 3600 = 60min * 60 sec if ( (time-$atime) > 3600) { #($sec,$min,$hour,$mday,$mon,$year)=((localtime($atime))[0..5]); #print "$sec,$min,$hour $mday,$mon,$year :$file\n"; unlink($file); $num++; } #last if ($num==10); } closedir(DIR); print "number of files deleted: $num\n";