0

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
  • 3
  • 2
  • 1
    Relating https://superuser.com/q/1609611/513541 – Jeff Schaller Jun 14 '23 at 02:38
  • While this question has been answered, the question is very, very unclear and I do not think it will be much value going forward unless it is edited to be more clear. – music2myear Jun 15 '23 at 04:06
  • Probably an issue with the way I posted the question. Basic requirements are to find a file or a list of files in AIX and print the list in seconds old. The above find command shows the requirement. – mdtoro Jun 15 '23 at 13:14
  • Does this answer your question? [Find top N oldest files on AIX system not supporting printf in find command](https://superuser.com/questions/1609611/find-top-n-oldest-files-on-aix-system-not-supporting-printf-in-find-command) – phuclv Jun 23 '23 at 17:48

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";
  }
}
Jeff Schaller
  • 194
  • 1
  • 3
  • 12
  • Very useful as it shows the concept is possible. Might need some tweaks Wildcard wouldn't work but partially specifying the file name with a wild card did work. ./getfiletime.pl /opt * 1 no output ./getfiletime.pl /opt fi* 1 /opt/file;1686773770;253 – mdtoro Jun 14 '23 at 20:21
  • You would want to quote any wildcard you pass to this script, to protect it from being expanded by your shell. – Jeff Schaller Jun 14 '23 at 20:58