Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#! /usr/bin/perl -w
my $TESTING=1;
my $CONTROL_FOLDER = '/opt/mailmanage/data';
my $CLEANUP_FILE = 'mail_cleanup.list';
my $CONFIG_FILE_NAME = 'mailmanage.cfg';
my $TEMP_CLEANUP_TIME = 7;
sub getScriptLocation {
use strict;
use File::Spec::Functions qw(rel2abs);
use File::Basename;
return dirname(rel2abs($0));
}
sub readConfig {
my $scriptLocation = &getScriptLocation();
my $return = '';
if ( -e "$scriptLocation/$CONFIG_FILE_NAME" ) {
open CFG,"<$scriptLocation/$CONFIG_FILE_NAME" or die "Could not read $scriptLocation/$CONFIG_FILE_NAME: $!\n";
$return = join ( '', <CFG> );
close CFG;
}
return $return;
}
sub getFoldersToProcess {
my $folderListFile = shift;
my @folders = ();
open DATA, "<$folderListFile" or die "Could not read $folderListFile: $!\n";
@folders = grep { ! /^#/ } <DATA>;
close DATA;
chomp @folders;
return @folders;
}
sub cleanFolder {
my $folderToProcess = shift;
my @list;
if ( $TESTING ) {
@list = `find $folderToProcess -type f -mtime +$TEMP_CLEANUP_TIME -print`;
} else {
@list = `find $folderToProcess -type f -mtime +$TEMP_CLEANUP_TIME -print -exec rm \\{\\} \\;`;
}
return scalar( @list );
}
$config = &readConfig();
eval( $config );
$CLEANUP_FILE = "$CONTROL_FOLDER/$CLEANUP_FILE";
my @foldersToProcess = &getFoldersToProcess( $CLEANUP_FILE );
my $totalDeleted = 0;
print "TEST MODE; no files deleted\n" if $TESTING;
print "Cleaning files older than $TEMP_CLEANUP_TIME Days\n";
foreach my $folder ( @foldersToProcess ) {
my $deleted = &cleanFolder( $folder );
print "$folder\t$deleted\n";
$totalDeleted += $deleted;
}
print "Deleted $totalDeleted files\n";
1;