watch a subdirectory with incron

4.9k Views Asked by At

I use incron for watch a direcory and run a script if a file is added.
In /etc/incron.d/ I have a file with:

/home/pat0/downloads IN_CLOSE_WRITE /var/www/owncloud/scanOC.sh pat0

It's ok when I add a file in /home/pat0/downloads but, if I create a subdirectory and I add in a file no thing run.

For exemple /home/pat0/downloads/test/myfile.txt is not seen.

How can I watch /home/pat0/download and all its future subdirectories and files?

3

There are 3 best solutions below

0
On BEST ANSWER

No, I don't think this is possible with incron. Please check with Watcher.

Watcher is a daemon that watches specified files/folders for changes and fires commands in response to those changes. It is similar to incron, however, configuration uses a simpler to read yaml file instead of a plain text file. It's also written in Python, making it easier to hack.

1
On

According to the man page:

... Also, there is the symbol recursive=false. This symbol limits the observation on the specified directory and does not include subdirectories.

This rather implies that in the absence of such a flag incrond will check sub-directories. However my experience is that it does not. Sadly, specifying recursive=true also does not work.

1
On

Recursive directory watching in incron is a new feature added in version 0.5.12 (see https://github.com/ar-/incron/blob/master/CHANGELOG):

0.5.12 2015-02-01

  • added recursive directory watching
  • added configuration parameters: recursive, dotdirs and loopable
  • added upstart script
  • extended manpages and readme