A very basic tail -f implementation

From: James F.Hranicky [mailto:jfh@cise.ufl.edu]
Sent: Wednesday, July 31, 2002 3:50 PM
To: ruby-talk@ruby-lang.org
Subject: Re: A very basic tail -f implementation

I could try to document a little more in the best english
I鈥檓 capable
of. That is, it will probably be quite awful. :wink:

A couple of suggestions:

  • Check for rotation by checking for changes in the inode number

This is proving difficult in practice because, as the Pickaxe says, the
File::Stat info is recorded at the moment the File::Stat object is created;
changes made to the file after that point will not be reflected. This
applies to filehandles as well, as experimentation has shown. Simply
calling the class method won鈥檛 work either because that requires the
filename which, by that point, has already changed.

If I鈥檓 doing something wrong, I鈥檇 love to know how to make this work!

  • Allow tailing from arbitrary points in the file by lines, e.g

Heh - funny you should mention it. I already submitted a very similar
approach to Florian. :slight_smile:

Regards,

Dan

路路路

-----Original Message-----
On Wed, 31 Jul 2002 21:02:04 +0900 > Florian Frank flori@eavesdrop.ping.de wrote:

That鈥檚 true, you just have to stat the actual filename everytime and
check against the current filehandle.

I wrote my own very simple tail -f thingy in Ruby a few months back,
and was recently working on improving it when I noticed that Florian
released his version. Here鈥檚 what I have so far. Anyone can use any
of it however they want.

t.txt (2.65 KB)

路路路

On Thu, 1 Aug 2002 21:23:09 +0900 鈥淏erger, Daniel鈥 djberge@qwest.com wrote:

- Check for rotation by checking for changes in the inode number

This is proving difficult in practice because, as the Pickaxe says, the
File::Stat info is recorded at the moment the File::Stat object is created;
changes made to the file after that point will not be reflected. This
applies to filehandles as well, as experimentation has shown. Simply
calling the class method won鈥檛 work either because that requires the
filename which, by that point, has already changed.

If I鈥檓 doing something wrong, I鈥檇 love to know how to make this work!


Jim Hranicky, Senior SysAdmin UF/CISE Department |
E314D CSE Building Phone (352) 392-1499 |
jfh@cise.ufl.edu http://www.cise.ufl.edu/~jfh |


鈥淕iven a choice between a complex, difficult-to-understand, disconcerting
explanation and a simplistic, comforting one, many prefer simplistic
comfort if it鈥檚 remotely plausible, especially if it involves blaming
someone else for their problems.鈥
鈥 Bob Lewis, Infoworld

Right. You also ought to check the device number, in case the file
is somewhow moved to another device and ends up with the same inode
number. At least, that鈥檚 what I did when I added the 鈥-F鈥 option
to tail(1) in NetBSD. Maybe I鈥檓 just anal-retentive. :slight_smile:

Also, you might want to check to see if the file has been shortened,
in case the writer truncates it and starts writing again at the
beginning.

cjs

路路路

On Thu, 1 Aug 2002, James F.Hranicky wrote:

On Thu, 1 Aug 2002 21:23:09 +0900 > 鈥淏erger, Daniel鈥 djberge@qwest.com wrote:

- Check for rotation by checking for changes in the inode number


That鈥檚 true, you just have to stat the actual filename everytime and
check against the current filehandle.


Curt Sampson cjs@cynic.net +81 90 7737 2974 http://www.netbsd.org
Don鈥檛 you know, in this new Dark Age, we鈥檙e all light. --XTC