in reply to Re^2: how to log a process
in thread how to log a process
Update: could be better: have fun!#!/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 ### }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to log a process
by zimbot (Initiate) on May 28, 2009 at 23:36 UTC | |
by Marshall (Canon) on May 29, 2009 at 00:10 UTC | |
by zimbot (Initiate) on Jun 01, 2009 at 13:12 UTC | |
by Marshall (Canon) on Jun 01, 2009 at 18:31 UTC |