Created
June 30, 2012 19:06
-
-
Save vivus-ignis/3025124 to your computer and use it in GitHub Desktop.
Cut big logs to chunks
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
#!/usr/bin/env ruby | |
log = ARGV[0] | |
chunk = 1024 * 1024 * 50 # 50 Mb | |
cursor = 0 | |
cnt = 1 | |
file_size = File.stat(log).size | |
while cursor <= file_size | |
cnt_p = cnt < 10 ? "0#{cnt}" : cnt | |
copy_to = File.join( File.dirname(log), "#{File.basename(log)}_#{cnt_p}" ) | |
IO.copy_stream(log, copy_to, chunk, cursor) | |
puts "Written chunk to #{copy_to}" | |
cursor += chunk | |
cnt += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment