I have an inotifywait script that monitors a ftp upload directory and whenever a new file is uploaded it sets the correct permissions.
I do this because the remote client forces wrong file modes and preventing the ftp server to accept chmod commands causes the remote client to spit out bogus errors.
so my last resort is an inotify script but that causes yet another problem, here it is:
#!/bin/bash
inotifywait -mrq -e ATTRIB --format "%w%f" /home/user/upload/ | while read FILE; do
if [[ -f "$FILE" ]];then
chown user:apache "$FILE" && chmod 640 "$FILE"
fi
done
so my guess what goes wrong here is that once the file is uploaded and chmodded by the client the ATTRIB option gets triggered (as it is supposed to) but the resulting chmod in my own script causes the ATTRIB option to be triggered again... causing a recursive loop.
is there a way to make clear to inotifywait that it should ignore its own actions preventing this loop?