OH3: How to find out if file is younger than 60s

I have an old (OH 2.5) rule where I parse a file within al folder.
In OH3 the “executeCommandLine” are not working any more, allthough I tried to adapt them to OH3.
They now look:

var String result
result = executeCommandLine(Duration.ofSeconds(1),"stat -t -c%Z /var/tmp/tdrm.log")

I need to check if a the file /var/tmp/tdrm.log is younger than e.g. 60s.
How can I do that?


Use a small shell script like:


NOW=`/bin/date "+%s"`
TIMESTAMPFILE=`/usr/bin/stat -t -c%Z /var/tmp/tdrm.log`
result=$(expr ${NOW} - ${TIMESTAMPFILE})
echo $result

to calculate the time(differnce).
Instead of echo $result you could add a check like

if [ $result -lt 60 ]
       echo "is younger than 60 seconds"
       echo "is not younger than 60 seconds"

Thank you very much!!!
I will test it today!!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.