• Uncategorized

About python : how-to-know-if-file-changed-or-truncated-in-linux

Question Detail

I want to write a python tool which work as tail (read log content constantly)

There are two problems need to handle.

  1. the log file might be backup and truncated
  2. the log file might be moved and recreated

I need to sense these two situation do different action. if situation 1 then seek the to file begin to. if situation 2 then close file handler and open new one

I can use a while true to constantly monitor the file inode and file size to identify which situation happened. But it is too heavy

Is there any other way? Does linux has any single or event to tell file changed or truncated?

The watchdog tool can do this but I can not install it.

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.