Re: Files not found




"John" <nyrinwi@xxxxxxxxx> wrote in message
news:47d2a3e5$0$4968$4c368faf@xxxxxxxxxxxxxxxxx
Leslie Rhorer wrote:
I have a little puzzle I need to solve. I want to look in a
directory and take action if no files less than 5 minutes old are found.
If I were looking for files which are younger than five minutes, I could
just do

find ./ -cmin -5 -exec do-something '{}' \;

Similarly, if I wanted it to take action if it finds files older than
5 minutes I could do

find ./ -cmin +5 -exec do-something '{}' \;

What I need, however, is to take action if there are no files less
than 5 minutes old, regardless of whether there are files more than 5
minutes old or not.

Is there a reason why it has to be done by find?

No, not at all. Indeed, it's probably best not.

Why not this Bash pattern?

files=$(find ./ -cmin -5 -print)

or if you prefer an array...

files=($(find ./ -cmin -5 -print))

You can then take whatever action you like; e.g.

if [ ${#files} -eq 0 ]; then ... # non array

That's exactly what I needed. I tried various evaluations of the output of
find, but none of them worked. Thanks!

This is all Bash stuff, consult the bash documentation for more info.

I did, I just couldn't get any of the evaluations to work.


If you want to get fancy, you can look into inotify to setup a kind of
watchdog, which sounds like what you may be looking for. I think Python
has an inotify module.

No, I just have an hourly cron script with a section that should not run
unlesss none of the files in the directory are being modified by any
application. All the applications in use on the directory stream data
continuously to completion, so if the file's ctime is more than 5 minutes in
the past, it's safe to assume it's not being modified. Thanks again,
though.


.