in reply to inotify problem

Your code works for me on my gentoo system. I used
echo one >> foo echo two >> foo echo three >> foo
to make three separate changes to the file. If you are using an editor. It may be writing to the changes to a temp file; removing the original file; then renaming the temp file to the original name.

Replies are listed 'Best First'.
Re^2: inotify problem
by morgon (Priest) on Jun 05, 2012 at 21:23 UTC
    Thanks a lot for your point about the editor.

    In fact my code is working but I had been trying to track changes to a file made with vim.

    The problem was that I use a "backup"-option in my vimrc and what vim then seems to do is to move the original file to the backup-folder and continue to work on a copy. The copy has the same name as the watched file but of course a different inode-number, so subsequent changes are not detected by inotify.

    I wanted to use inotify to avoid polling but in the light of this I would also have to watch the directory to detect such things and the extra complexity is probably not worth it.

    Or is there another way to discover changes made to a file given by name (i.e. whose inode could change) apart from polling it?