09-23-05 02:01 AM
Hi,
I do a similar thing with cleaning up an ftp system every hour. The script
below can be modified for your use. It is a PERL script. Instead of
unlinking the files, just do a move of the files. The script is pretty easy
to modify.
Craig
------------------------------------------------------------snip------------
-----------------------------------------------
#!/usr/bin/perl -w
use Time::Local;
use File::stat;
open OUTFILE, ">/home/admin/cleanup/ftpdirs.lst" || die "$!\n";
open EXCLUDE, ">/home/admin/cleanup/exclude.lst" || die "$!\n";
@DIRS = `find $ARGV[0] -type d`;
foreach (@DIRS) {
chomp;
unless (/lib/ || /etc/ || /bin/ || /admin/) {
select OUTFILE;
print "$_\n";
select STDOUT;
next;
} else {
select EXCLUDE;
print "$_\n";
select STDOUT;
}
}
close OUTFILE;
close EXCLUDE;
open INFILE, "/home/admin/cleanup/ftpdirs.lst" || die "Cannot open file
$!\n";
# get the path
@path = <INFILE>;
# set max age in seconds;
$max_age=864000;
# get the current time in Epoch seconds
$tm=timelocal(localtime);
# get the directory contents
foreach $DIR (@path) {
chomp $DIR;
chdir $DIR;
@directory=glob("*");
# process each entry in the directory
foreach (@directory) {
chomp; # remove new line
$filestat=stat($_); # stat the file
if(-f) { # if it IS a file
$writetime=$filestat->mtime; # get the last mod'd time
$age=$tm-$writetime; # calculate the file age
if($age>$max_age) { # older than max_age?
print "$DIR\/$_\n";
unlink($_); # delete the file
}
}
}
}
----== Posted via webservertalk.com - Unlimited-Uncensored-Secure Usenet New
s==----
http://www.webservertalk.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
[ Post a follow-up to this message ]
|