Created
April 23, 2015 13:41
-
-
Save varp/8ed92c76370944f66468 to your computer and use it in GitHub Desktop.
Split apache access log file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
apache_log = ARGV[0] unless ARGV.empty? | |
@cur_date = nil | |
@next_date = nil | |
File.open(apache_log) do |f| | |
for line in f | |
if line.match /(\d{1,2}\/\w{1,3}\/\d{1,4})/ | |
@next_date = Date.strptime($~[1], "%d/%b/%Y").strftime("%d-%m-%Y") | |
unless @cur_date == @next_date | |
@cur_date = @next_date | |
begin | |
log.close | |
rescue NameError | |
log = nil | |
end | |
log = File.new "access-#{@cur_date}.log", "w" | |
else | |
log.write(line) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment