#!/usr/bin/env ruby require 'gdbm' require 'time' require 'syslog' ILOGF = '/nwp/p0/incomplete/obsbf-log.db' LLOGF = '/nwp/p0/latest/obsbf-log.db' now = Time.now.utc logf = if File.exist?(ILOGF) then ILOGF elsif File.exist?(LLOGF) then LLOGF else STDERR.puts("missing #{ILOGF} and #{LLOGF}") puts "535" exit 0 end begin maxval='1970-01-01T000000Z' GDBM::open(logf) {|db| db.each{|k,v| next unless /^\d\d\d\d-\d\d-\d\dT/ === v maxval=v if v>maxval } } maxval="#{$1}:#{$2}:#{$3}" if /^(\d\d\d\d-\d\d-\d\dT\d\d)(\d\d)(\d\dZ)/ === maxval diff = now - Time.parse(maxval) rescue ArgumentError STDERR.puts("malformatted time #{maxval}") puts "535" exit 0 rescue Errno::EAGAIN mtime = File.mtime(logf).utc diff = now - mtime Syslog.open('wis-browse', Syslog::LOG_PID, Syslog::LOG_NEWS) do |log| log.warning(format("GDBM busy, mtime %s used", mtime.to_s)) end end if diff > 300 then Syslog.open('wis-browse', Syslog::LOG_PID, Syslog::LOG_NEWS) do |log| log.info(format("%.1fs from last bulletin %s", diff, maxval)) end end # 出力 printf "%6.3f\n", diff