Monitor Directory for Changes Monitor Directory for Changes unix unix

Monitor Directory for Changes


Look at inotify.

With inotify you can watch a directory for file creation.


First make sure inotify-tools in installed.

Then use them like this:

logOfChanges="/tmp/changes.log.csv" # Set your file name here.# Lock and loadinotifywait -mrcq $DIR > "$logOfChanges" &IN_PID=$$# Do your stuff here...# Kill and analyzekill $IN_PIDwhile read entry; do   # Split your CSV, but beware that file names may contain spaces too.   # Just look up how to parse CSV with bash. :)   path=...    event=...   ...  # Other stuff like time stamps?   # Depending on the event…   case "$event" in     SOME_EVENT) myHandlingCode path ;;     ...     *) myDefaultHandlingCode path ;;done < "$logOfChanges"

Alternatively, using --format instead of -c on inotifywait would be an idea.

Just man inotifywait and man inotifywatch for more infos.

You can also use incron and use it to call a handling script.


One solution I thought of is to create a "file listener" coupled with a cron job. I'm not crazy about this but I think it could work.