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
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