diff options
author | Peter Palfrader <peter@palfrader.org> | 2006-10-28 02:22:52 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2006-10-28 02:22:52 +0000 |
commit | 579690999a96110ac0b66bce2d7533ab5b760ce4 (patch) | |
tree | d620c4fc10e985696b3b963fc09d8cec2f57436e /bin | |
parent | 0fe9695abce1699edc19cf4ad1a8eaee0d94a722 (diff) |
Add weblogs-cat-and-remove
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@236 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/weblogs-cat-and-remove | 48 |
1 files changed, 48 insertions, 0 deletions
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] <clientname> <vhostname>" + 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 |