summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/weblogs-cat-and-remove48
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