How to tell if a file is older than 30 minutes on AIX

aixdatefind

I'd like to write a shell script in ksh or bash which exits with 1 if a specific file is older than 30 minutes. (Last modification time is older than half hour).
It would be easy on a Linux or a modern unix, but I have to do it on AIX 5.2 version.

So the constraints:

  • there is no -mmin -mmax options in 'find'
  • there is no -d option in touch (touch -d '30 minutes ago' temp then find ! -newer temp doesn't work)
  • there is no 'stat' command
  • there is no %s parameter in the 'date' command (date +%s doesn't work)
  • I'm not allowed to install any software

Could you please help how can I do it with these constraints?

Best Answer

I can do it using just touch, test, and date. (tested on AIX 5.3.0.0)

First you need to create a file 30 minutes in the past (Unfortunately, this requires prior knowledge of the current timezone on the machine. But you may be able to work that into things if need be.)

In this example, the current timezone is EST5EDT (GMT-4). If you're lucky, the machine timezone will be set at GMT and you can just use TZ=00:30:

-bash-3.00# date
Mon 26 Mar 14:22:31 2012
-bash-3.00# touch -t `TZ=04:30 date '+%Y%m%d%H%M.%S'` foo
-bash-3.00# ls -al foo
-rw-r--r--   1 root     system            0 26 Mar 13:52 foo

Now use test to compare the dates:

-bash-3.00# test '/smit.log' -ot foo && echo 'smit.log is older than 30min'
smit.log is older than 30min
Related Topic