I want to write a python tool which work as tail (read log content constantly)
There are two problems need to handle.
- the log file might be backup and truncated
- 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.