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
, anddate
. (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
:Now use test to compare the dates: