in reply to Delete on age of files Help!

From the doc for -M:
-M Script start time minus file modification time, in days.
So, your 360 is 360 days, not 6 minutes. I believe fractional days work with -M (0.004 is about 6 minutes).

Perhaps stat. I Super Searched and found script for scanning folder and sending a warning if a file within it is older than 5 minutes

Replies are listed 'Best First'.
Re^2: Delete on age of files Help!
by Anonymous Monk on Jan 16, 2011 at 04:00 UTC
    Hi, even this doesnt work:
    #!/usr/bin/perl -w use strict; use File::stat; my $mytime=(time); my $file_stat; ... opendir(DIR, $all_session) or die "Couldn't open directory, $!"; while (my $sessions = readdir DIR) { # Use a regular expression to ignore files beginning with a peri +od next if ($sessions =~ m/^\./); next if ($sessions !~ /^cgisess_[a-f0-9]{32}$/); #if( -M qq{$all_session/$sessions} > 360){ # 6 minutes #print "Del these session files: $sessions<br>"; #} if ($file_stat = (stat $sessions)[9]){ if ($file_stat >= ($mytime - 300)) { print "File older than 5min found. The file name is $ses +sions"; last; } } } closedir DIR; ...
      stat returns something different:
      stat[ 9 ] is an absolute time (from epoch).
      Perl: Stat
Re^2: Delete on age of files Help!
by Anonymous Monk on Jan 16, 2011 at 04:05 UTC
    I guess this line should work:
    if( -M qq{$all_session/$sessions} > 0.004){ print "del this $sessions +";} %6 minutes
    How did you get 0.004?
      How did you get 0.004?
      1 day = 1440 minutes (24hours/day x 60minutes/hour)
      6/1440 = 0.004 (roughly)