1

I was thinking this was going to be rather easy, but it's turn out not to be.

I have a mounted network server that has inotifywatch running on it watching a folder. I was wanting to have this set up so that anyone on the network with access to this server could drop a file into the watched folder and have it execute a script. Unfortunately it doesn't seem to trigger unless the file was moved on the server itself.

Is there any way to make inotify watch a folder in a way that if any file, from anywhere, triggers the inotify event? Or should I look into something else?

For reference, here is what I'm using in a shell script:

inotifywait -m --format '%f' -e moved_to "/mnt/server/folder/" |
while read NAME
do
     echo $NAME
done
Samsquanch
  • 8,866
  • 12
  • 50
  • 89
  • @jwpat7 No event is triggered. I changed the code to `inotifywait -m --format '%e' "/mnt/server/folder/` and moved a file from my machine to the servers watch directory, and no event triggered. I then moved a file from within the server to the watch directory and got a `moved_to` event as I would expect. It might be worth noting that I was SSHed in to move the file when the event fired. When I move a file from my machine within the server (i.e. drag and drop in Finder) no event fires. – Samsquanch Oct 15 '12 at 22:43
  • If on your machine you drag & drop to the watch folder while the inotifywait is running on the server, does inotifywait report events? – James Waldby - jwpat7 Oct 16 '12 at 00:49
  • Refer this http://stackoverflow.com/questions/4231243/inotify-with-nfs – iruvar Oct 16 '12 at 01:11

2 Answers2

0

I ended up setting up rsynch in a cron job to copy over the folder from the network every few minutes, then use inotifywatch to pick up new files from there.

Samsquanch
  • 8,866
  • 12
  • 50
  • 89
0

inotifywait workaround for mounted drives :/

saveloop2 ./03_packages.js "clear" "node ./03_packages.js"

#!/usr/bin/env bash

if [[ "$#" -lt 2 ]]; then
    echo -e "\e[91;48;5;52musage: saveloop <watchfile> <execution script> [another] [another] ✗✗✗\e[0m\n"
    echo -e "example: saveloop  .gitalias  \"foo param1 param2\" [\"command2\"] [\"command2\"]"
    echo -e "Note: each command with its params to be in quotes."
    exit
fi

while :
do
    oldTimestamp=$timestamp
    timestamp=$(stat -c %Y $1)
    if [[ $oldTimestamp != $timestamp ]]; then
        $2
        $3
        $4
    fi
    sleep 1
done

Frank N
  • 9,625
  • 4
  • 80
  • 110