
October 2nd, 2012, 08:44 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 5
Time spent in forums: 1 h 15 m 36 sec
Reputation Power: 0
|
|
|
Trying to use File:Tail with Ruby
Hi
I am a newbie and I am dabbling with scripting and using Ruby to monitor some logs and ran into a script that I thought would do the job. This is the script I found -
-----------------------------------------------------------
require 'rubygems'
require 'pony'
require 'file/tail'
def fatal_check(file, pattern)
File::Tail::Logfile.open(file, :backward => 0) do |log|
log.tail do |line|
date = `date +%D-%T`
Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => "There was a nasty error on #{date}", :body => line)
end
end
end
fatal_check(File.dirname(__FILE__) + "/test.log", /FATAL/)
-----------------------------------------------------------
I don't understand how the method is monitoring the pattern as I dont see it being called in the method. From trying it out, it appears that any new lines causes an email to send.
Any help in the right direction would be helpful
|