tags:

views:

463

answers:

3

G'day,

I need to see if a specific file is more than 58 minutes old from a sh shell script. I'm talking straight vanilla Solaris shell with some POSIX extensions it seems.

I've thought of doing a

touch -t YYYYMMDDHHmm.SS /var/tmp/toto

where the timestamp is 58 minutes ago and then doing a

find ./logs_dir \! -newer /var/tmp/toto -print

We need to postprocess some log files that have been retrieved from various servers using mirror. Waiting for the files to be stable is the way this team decides if the mirror is finished and hence that day's logs are now complete and ready for processing.

Any suggestions gratefully received.

cheers,

+2  A: 

You can use different units in the find command, for example:

find . -mtime +0h55m

Will return any files with modified dates older than 55 minutes ago.

alxp
find has a -mmin predicate, eg. -mmin +58
Hasturkun
A: 

A piece of the puzzle might be using stat. You can pass -r or -s to get a parseable representation of all file metadata.

find . -print -exec stat -r '{}' \;

AFAICR, the 10th column will show the mtime.

Marcelo Morales
@Marcelo, isn't stat a Linux command?
Rob Wells
I don't see `stat(1)` dictated by POSIX/SUS, but BSD definitely has it. Not all the same option switches as GNU, but that's unsurprising.
ephemient
A: 

Since you're looking to test the time of a specific file you can start by using test and comparing it to your specially created file:

test /path/to/file -nt /var/tmp/toto

or:

touch -t YYYYMMDDHHmm.SS /var/tmp/toto
if [/path/to/file -nt /var/tmp/toto]
   ...
Aaron Maenpaa