Problem with File::Tail (no new lines getting processed)

Hi everyone,

I just started learning Ruby a couple days ago. It's pretty cool! I went to school and learned OO C++. Anyway, I'm trying to make a script that tails a log file (output from syslog-ng) and grabs spam messages. Eventually it will create some amavisd-new statistics. I'm having trouble tailing the file, though. When I start the program it spits out the entire file (unless I have rewind in the open() call), then sits there "tailing" but no new lines get displayed. Normal `tail` works from the console... This is all on a FreeBSD 4.10 system.

Here is my script; I was using the commented-out portion earlier but it wasn't working so I dumped in an example almost verbatim. It still doesn't work correctly:

#!/usr/local/bin/ruby

require 'file/tail'

File::Tail::Logfile.open("/var/log/all.log", :rewind => 10) do |log|
    log.tail { |line| puts line }
end

#File::Tail::Logfile.open("/var/log/all.log") {
# |file|

···

#
# file.tail {
# |line|
#
# if /SPAM=TAG/i.match(line)
# puts line
# end
# }
#}

Thanks for any advice,

Josh

I could confirm this behaviour on a local FreeBSD installation. I think
you found a bug: If EOFError occurs on FreeBSD the tailed file handle
is tagged with an error flag. So further reading isn't possible before
calling clearerr on it. Because I cannot do this directly from Ruby I
just used the seek method to clearerr as a side effect. This seemed
rather hackish to me: Perhaps it would be better to use a dedicated
method for this. Or should Ruby take care of clearing the handle after
an EOFError occurs, so users don't have to? I am not quite sure...

Could you try this hotfixed version?

http://www.ping.de/~flori/programs/ruby/file-tail/file-tail-0.1.1.tgz

···

On 2004-09-01 06:08:57 +0900, Josh Endries wrote:

having trouble tailing the file, though. When I start the program it
spits out the entire file (unless I have rewind in the open() call),
then sits there "tailing" but no new lines get displayed. Normal
`tail` works from the console... This is all on a FreeBSD 4.10 system.

--
lambda { |c| lambda { |f| f[f] } [ lambda { |f| c[lambda { |x| f[f] } ] }] }

Florian Frank wrote:

Could you try this hotfixed version?

http://www.ping.de/~flori/programs/ruby/file-tail/file-tail-0.1.1.tgz

This version works great (or, at least, as expected). I had a feeling it had something to do with FreeBSD. :slight_smile:

Thanks,
Josh