I have been running inotify-wait on my ftp server in byobu to monitor a folder, move data, and send email notifications for a few months without problems. Since I started this I have added 3 more folders that I monitor and I would like to start running inotify-wait as a daemon instead of in byobu sessions. I modified my script to be easier to only require a single variable to be changed and to run as a daemon. Unfortunately it now does nothing. I was hoping someone with some experience could take a look and tell me where Ive gone wrong.

#!/usr/bin/env bash


inotifywait -q\
-d "$dir" \
-o "$log" \
-e close_write --format %f . | while IFS= read -r file; do
cp -p "$file" "$target"
mv "$file" "$archive""$(date +%F-%T)"
  • "Does nothing" is a bit difficult to debug. Have you tried set -o errexit? Have you tried printing a string when you enter the loop? Have you tried touching a file in the directory and seeing if the loop progresses? How are you running this as a daemon? Are you sure inotifywait is on the PATH in the context you're running it? – l0b0 Jul 21 '15 at 16:49
  • I think you are correct that it the -d does not accept the "$dir" like the -m does in my previous script. I have been using touch to create files in the $dir and inotifywait does not appear to recognize the change. – rfinterference Jul 21 '15 at 17:29

Which version of inotifywait are you using? According to this man page -d specifies that you want to run it as a daemon, but it doesn't take an argument value ("$dir"). Also with -o "$log" it will be saving output to the log file and not sending it to standard output. Make sure you have a working inotifywait command before continuing with the script - ideally add a test which watches some files in a temporary directory (or re-implement in a better language like Java, Python or Ruby).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.