1

AIX 7.2 Looking to recreate the below on AIX.

 find /etc -maxdepth 1 -iname "*conf" -type f -mmin +5  -printf '%p;%T@\n' | awk -F ';' -v time="$( date +%s )"  '{ print $1";"$2";" (time-$2 ) }'

/etc/rsyslog.conf;1640302499.0000000000;46381761

conf files are just and example of finding a list of specific files that may be older than a set number of seconds. Could be as low as 300 seconds or 43200 seconds or more.

mdtoro
  • 13

1 Answers1

0

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"; } }