If I add lines through cat, then the script reads the new lines. But if I edit the file through a vim editor, then the script does not see any new lines in the file and issues an EOF. Why does the script behave this way and do not see new lines?

Indeed, vim changes the inode. I checked other console editors: mcedit, nano they like cat edit the existing file and not replace it with a new one. Why does vim behave this way? I wanted to use Linux::Inotify2 to track the modification of the file, but if the file is ruled in vim then it is without meaning.
– DmitriySep 10 '18 at 22:32

1

Re "Why does vim behave this way?", I'm guessing it saves to a temporary file, then renames the temporary file. This way, you don't risk losing both the new and the old file.
– ikegamiSep 10 '18 at 22:42

If adding set backupcopy=yes to ~/.vimrc file, then vim will not replace the file
– DmitriySep 10 '18 at 22:57

1

You can get notified of the file creation if you monitor the directory, right?
– ikegamiSep 11 '18 at 3:58

@Dmitriy Also, there are yet other flags which can detect metadata change, along with a good selection of other events of interest. You want to add them anyway. While a directory monitor on its own can be used to handle (nearly?) all of that, too.
– zdimSep 11 '18 at 5:31