3

My problem is very similar this one: inotify not fast enough

Except I am running inotify in a remote shell.

I need to monitor for file change on machineA from machineB. machineB has ssh access to machineA but not the other way around.

while true; do
    FILEPATH=$(ssh -i key.pem A@machineA "inotifywait -m -e close_write $REMOTE_WATCH_DIR --format '%w%f'")
    echo $FILEPATH
done

In the above code, $FILEPATH is always empty.

If I don't place -m then it will work, but just for one file. As mentioned in this problem: inotify not fast enough I need to handle multiple file changes too.

Any suggestions on how to make it work? I need to trigger inotify over multiple files in a remote shell and get back a list of files which were modified in the remote machine.

zengr
  • 818

1 Answers1

3

Figured it out:

while true; do
    echo "inotifywait -m -e close_write $REMOTE_WATCH_DIR --format '%w%f:%f'" | ssh -i key.pem A@machineA /bin/bash |
    while read file
    do
        process_data $file
    done
done
zengr
  • 818