#!/usr/bin/ruby require 'optparse' ROOT = '/srv/www/vhosts' FORSTATS_DIR = "logs-for-stat" READBLOCKSIZE = 4096 @unlink = true def show_help(parser, code=0, io=STDOUT) io.puts "Usage: #{$0} [-n] " io.puts parser exit(code) end ARGV.options do |opts| opts.on_tail("-h", "--help", "Display this help screen") { show_help(opts) } opts.on("-n", "--no-remove" , "Do not remove files after printing them") { @unlink = false } opts.parse! end show_help(ARGV.options, 1, STDERR) unless ARGV.length == 2 client = ARGV.shift vhostname = ARGV.shift root_forstats_dir = ROOT+"/"+client+'/'+FORSTATS_DIR [ROOT, ROOT+"/"+client, ROOT+"/"+client+'/'+FORSTATS_DIR].each do |dir| unless File.exist?( dir ) STDERR.puts "#{dir} does not exist" exit 1 end unless File.stat( dir ).directory? STDERR.puts "#{dir} is not a directory (or does not exist or something)" exit 1 end Dir.chdir(dir) end Dir.glob("#{vhostname}-access.log.*").sort.each do |filename| File.open( filename, "r" ) do |f| while r = f.read(READBLOCKSIZE) do STDOUT.write r end end File.unlink(filename) if @unlink end