#!/usr/bin/perl -w use strict; my $logfile = "script_logs/30DyDlt-LOG.txt"; open (LOGFILE, ">>$logfile") or die "Cannot open logfile $logfile for append $!"; my $dir = 'oven_web/iportal/cgi-bin/uploads'; opendir(DIR,$dir) || die "Can't open directory $dir $!"; my @files = grep{-f "$dir/$_"} readdir(DIR); my $current_date_time = time(); #this is seconds +- epoch value! my $thirty_days = 60 * 60 * 24 *30; #num seconds in 30 days foreach my $file(@files) { my $file_time = (stat("$dir/$file"))[9]; if ( $file_time < ($current_date_time - $thirty_days) ) { print "Deleting $dir/$file...\n"; #for the user on terminal unlink("$dir/$file") or die "unable to unlink file $file in $dir $!"; print LOGFILE "$dir/$file deleted\n"; } } #### foreach $file (readdir D) { if ((-M "$dir/$file" > 30) && !unlink("$dir/$file")) { print "Oh no!!!!!\n"; } # else it worked ### }