Document Monitoring with Ruby
Leave a Comment so far
Leave a comment
May 29, 2008, 3:13 pm
Filed under: Uncategorized
Filed under: Uncategorized
I have started a project at work to monitor log files and send any errors to the engineers. I played around with it in Ruby and in no time had the code below, which worked wonderfully. Unfortunately, due to the way this particular project is deployed, ruby was not an option. Feel free to use this if you need to monitor files for changes.
require 'ftools'
log_file = "test.log"
last_change = File.mtime(log_file)
while(true)
if File.readable?(log_file) && (file_time = File.mtime(log_file)) > last_change
last_change = file_time
puts "Log has been updated"
end
end
Advertisement
Leave a Comment
Leave a Comment so far
Leave a comment