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

J

Josh Endries

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
 
F

Florian Frank

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top