If I had to solve this on an AIX system, I'd again lean on perl. Since you're using -maxdepth 1
, there's no real need to get into the File::Find module here. I came up with a perl script that uses two essential functions:
glob
to match the expected filename pattern
stat
to extract the mtime of the files
If the script finds files that match the pattern that have a last-modified time older than the expected age, it prints them in the semicolon-delimited format you gave. Beware that semicolons (and newlines and other whitespace) are allowable characters in filenames, so be careful when dealing with the output.
#!/usr/bin/perl -w
# prints matching file mtime and age in seconds
use strict;
# expect 3 arguments:
# * a starting directory
# * a (quoted from the shell) wildcard for -iname
# * a cutoff age in seconds
if ($#ARGV != 2) {
die "Usage: $0 [ dir ] [ pattern ] [ age ]"
}
my ($start_dir, $pattern, $age) = @ARGV;
unless ($age =~ /^\d+$/ && $age > 0) {
die "$0: age must be a positive integer"
}
my $now = time();
my $cutoff = $now - $age;
foreach my $file (glob "${start_dir}/${pattern}") {
next unless -f $file;
my $mtime = (stat($file))[9];
if ($mtime < $cutoff) {
print "${file};${mtime};" . ($now - $mtime) . "\n";
}
}