Skip to content

Instantly share code, notes, and snippets.

@vivus-ignis
Created June 30, 2012 19:06
Show Gist options
  • Save vivus-ignis/3025124 to your computer and use it in GitHub Desktop.
Save vivus-ignis/3025124 to your computer and use it in GitHub Desktop.
Cut big logs to chunks
#!/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