[GTALUG] Watching a network folder: is there a smart way of doing this?

Stewart C. Russell scruss at gmail.com
Fri Feb 17 15:41:39 EST 2017


I need to watch a folder on a network share (a scanner) and see when new
files are created. There are a couple of special things about this location:

* It's over CIFS. There's nothing I can do about that. I think that
means I can't use Inotify.

* It doesn't have an accurate clock for timestamping. There's nothing I
can do about that, either.

* If the share is being written to by the device, it effectively
disappears: stat() complains loudly.

* It reuses the lowest available file name of the form
“EPSON%03d.(PDF|JPG)”, so synching the share to a sensible filesystem
might overwrite files accidentally.

* I don't need to watch it very often; a few times per hour would be fine.

I tried using Perl's File::ChangeNotify::Watcher, which is supposed to
pick the smartest method available. Unfortunately, this seems to be
calling stat() every two seconds, resulting in:

1. Messages (one per existing file on the share) saying that the scanner
has deleted them. This happens when someone starts scanning

2. An error message from stat() every two seconds while the device is
scanning

3. Messages saying that all of the old files (plus the new one) have
been created.

I was naïvely hoping for a mechanism that would report “Hey, you have a
new file called $filename” but that seems to have been a pipedream. What
do People Who Actually Know What They're Doing use, please?

cheers,

 Stewart



More information about the talk mailing list