Create a file in /etc/cron.daily named Cleanup
chmod 755 /etc/cron.daily/Cleanup
pico -w /etc/cron.daily/Cleanup
[Add the following code to the file:]
#!/usr/bin/perl
# /* August 23, 2002
# * Nathan Fowler
# * evilghost@packetmail.net
# * This script will clean-up the public files to ensure old files are deleted
# */
#Directory containing the files, must be a folder
$popauthspool = "/home/e-smith/files/ibays/public";
#Logfile to recored deleted files to.
$watcherlog = "/var/log/public_cleanup.log";
$date = localtime();
open(LOG,">>$watcherlog") || die("Can't open $watcherlog");
use File::stat;
@ips = ls $popauthspool;
foreach $ip (@ips) {
chop($ip);
$file = $popauthspool ."/". $ip;
$s = stat($file) || die "Can't stat($file) $!\n";
#Delete files 31 Days old. (60 * 60 * 24 * [Num Days] = The Value)
$modtime = $s->mtime + 2678400;
$now = time;
if($modtime < $now){
push(@expired,$ip);
}
}
foreach $expired (@expired){
$date = localtime();
print LOG "$date - Removing $expired\n";
unlink($popauthspool ."/". $expired);
}
close(LOG);
[Save the file]
To view the deleted files:
cat /var/log/public_cleanup.log|more
Hope this helped,
Nathan