bashinotify

"inotifywait -e close_write" not triggering even when tail shows new lines


I have a script:

nohup tail -f /somefile >> /soemeotherfile.dat &
nohup while inotifywait -e close_write /someotherfile.dat; do ./script.sh; done &

but it seems that script.sh is never activated despite input arriving at the tail of /somefile every 5 minutes. What is wrong with my script above?


Solution

  • From the inotifywait docs:

    • close_write

      A watched file or a file within a watched directory was closed, after being opened in writeable mode. This does not necessarily imply the file was written to.

    close_write only triggers when a file is closed (which is typically desirable: it reduces the chances of trying to read content while it's in a half-written state).


    tail -f /somefile >> /soemeotherfile.dat
    

    ...continually appends to someotherfile.dat. It does not close it after each individual write.

    Probably you want the modify event instead.