Re: Files not found



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?
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

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

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.

John
.