All pastes #622312 Raw Edit

Something

public text v1 · immutable
·published 2007-07-16 19:58 UTC
rendered paste body
#!/usr/bin/env ruby
#
class LOGGER
def self.info str
        puts str
end
end

 def read_log
    begin
      log_file = "/var/log/messages"
      Thread.current['active'] = true
      open("| tail -n 2 -f #{log_file}") do |log|
        while Thread.current['active']
          line = log.gets if select([log], nil, nil, 0.1)
          LOGGER.info(". #{line}") unless line.nil?
        end
        Process.kill("SIGHUP", log.pid)
      end
    rescue
      LOGGER.info("TRACKER ERROR: #{$!}")
    end
  end


  thr = Thread.new {read_log}
  sleep 2
  thr['active'] = false
  thr.join