Problem with find ! -newer

Hi,

I would like to find if a file called test.log is older than 10 min.

So i wrote :

#!/usr/bin/ksh
FICLOG="/home/uuu/result_test.log"
FIC="/home/uuu/test.log"

touch -t `perl -e 'use POSIX qw(strftime); printf("%s\n",strftime("%m%d%H%M",localtime(time-3600*0.17)));'` /tmp/ref_time.check.$$

if find $FIC -type f ! -newer /tmp/ref_time.check.$$ >> /dev/null 2>&1
then
DATE=`date "+%y/%m/%d %H:%M:%S"`
echo "$DATE :Problem_on_test.log" >> $FICLOG
fi

The problem is that it finds the test.log file even if it isn't older than 10 mn.

Thanks

Not exactly. The problem is that "find" does not use the exit code to indicate that it found something. The exit code indicates whether or not find was successful in looking for something. A non-zero exit code means that an error occurred and a error message was sent to stderr. You will need to count the lines that "find" sends to stdout. ("find" used to work the way you think it should. But Posix "fixed" it.)

36000.17 is pretty gross. 6010 is a bit better. Personally, I would just use 600.

Hi,

How do you suggest me to code the test ?

Many Thanks :slight_smile:

Since you're using a real shell, just do
if [[ $FIC -nt /tmp/ref_time.$$ ]] ; then