Can Inotify Tell Me Where a Monitored File Is Moved

iNotify how to detect move-out

You need to check for the IN_MOVED_FROM event and a following IN_MOVED_TO event. If the cookie is the same, the file has been renamed in the same folder. If you don't receive a IN_MOVED_TO event with the same cookie, the file has been moved outside of the watched folder.

Monitor Directory for Changes

Look at inotify.

With inotify you can watch a directory for file creation.

monitoring and searching a file with inotify, and command line tools

monitor mode (-m) of inotifywait may serve better here :

inotifywait -m -q -e create -e modify -e close log_directory |\
while read -r dir action file; do
...
done

monitor mode (-m) does not buffer, it just print all events to standard output.

To preserve the variables :

while read -r dir action file; do
echo $dir $action $file
done < <(inotifywait -m -q -e create -e modify -e close log_directory)

echo "End of script"


Related Topics



Leave a reply



Submit