How do I write a script to determine if a file is older than 30 minutes in /bin/sh?
Unfortunately does not the stat
command exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix
Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either.
Here's one way using
find
.The
find
command must be quoted in case the file in question contains spaces or special characters.Ok, no stat and a crippled find. Here's your alternatives:
Compile the GNU coreutils to get a decent find (and a lot of other handy commands). You might already have it as gfind.
Maybe you can use
date
to get the file modification time if-r
works?Alternatively, use the
-nt
comparision to choose which file is newer, trouble is making a file with a mod time 30 minutes in the past.touch
can usually do that, but all bets are off as to what's available.And finally, see if Perl is available rather than struggling with who knows what versions of shell utilities.
You can do this by comparing to a reference file that you've created with a timestamp of thirty minutes ago.
First create your comparison file by entering
replacing the timestamp with the value thirty minutes ago. You could automate this step with a trivial one liner in Perl.
Then use find's newer operator to match files that are older by negating the search operator