Skip to content

Instantly share code, notes, and snippets.

@ymek
Created February 8, 2011 19:05
Show Gist options
  • Save ymek/816986 to your computer and use it in GitHub Desktop.
Save ymek/816986 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
t = Time.now
logline = (%x{/usr/bin/tail -n12 /var/log/php/api_error_log}).scan(/^\[.*/).last
lhour = logline.match(/(\d{2}):/)[1].to_i
thour = t.strftime("%H").to_i
day = t.strftime("%d").to_i
if (lhour < (t.gmt_offset + 2) and thour > lhour)
hour = lhour.to_i
day += 1
elsif (lhour > thour)
hour = lhour.to_i
else
hour = t.strftime("%H").to_i
end
if day < 10
day = "0#{day}"
end
lines = [ ]
File.open('/var/log/php/api_error_log') do |fd|
begin
while (line = fd.readline)
if line =~ /^\[#{day}-#{t.strftime("%b")}-#{t.year}\s+#{hour}:\d{2}:\d{2}\]/
lines << line.chomp
end
end
rescue EOFError
fd.close
end
end
puts lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment