[plug] Monitoring files "tail"

Adam Davin bladebadger at westnet.com.au
Sun Nov 7 22:45:51 WST 2004


Good evening all,

I am currently writing a program (in java) to monitor a log file, much like the tail program. I have run into an issue which I have also noticed affects "tail".

If you use tail to monitor a file (for example syslog) and the file is renamed (eg log file rotation), tail stops receiving incoming log information. (my understanding on this, is that whilst the name has changed, the inode which tail is monitoring stays the same and thus it continues to monitor the renamed file rather than switching to the new file).

My question is then: how can I detect this change? For those who have used Java, I thought I might be able to query the file object (inFile.getAbsolutePath and inFile.getName() - where inFile is the file object), but this still seems to return the original name used to create the file. I thought about creating a temporary file object with the filename to check the size of the new file against the old file, but this seems to be an awful lot of wasted overhead. 
	File tempFile = new File("filename");
	if (tempFile.length() < inFile.length()) {
		.. close and reopen the file handle...
	}

Any thoughts would be greatly appreciated!

Thanks in advance,

Regards, 

-- 

Adam Davin





More information about the plug mailing list