From 579690999a96110ac0b66bce2d7533ab5b760ce4 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 28 Oct 2006 02:22:52 +0000 Subject: Add weblogs-cat-and-remove git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@236 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- bin/weblogs-cat-and-remove | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 bin/weblogs-cat-and-remove diff --git a/bin/weblogs-cat-and-remove b/bin/weblogs-cat-and-remove new file mode 100755 index 0000000..bc9489f --- /dev/null +++ b/bin/weblogs-cat-and-remove @@ -0,0 +1,48 @@ +#!/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 -- cgit v1.2.3