inotify with network server
Asked Answered
H

2

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
Hatchet answered 15/10, 2012 at 22:31 Comment(3)
@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.Hatchet
If on your machine you drag & drop to the watch folder while the inotifywait is running on the server, does inotifywait report events?Faience
Refer this https://mcmap.net/q/278494/-inotify-with-nfsThievery
H
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.

Hatchet answered 17/10, 2012 at 15:0 Comment(0)
C
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

Curia answered 4/9, 2022 at 10:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.