#!/usr/bin/env ruby #------------------------------------------------------------------------------ # will look in dirname for the request files, for each request file # will call root script to do the concatenation # last check: 2004-08-01 # # example: # -------- # cdfopr/OfflineMon/scripts/parse_sam_farm_logs -d input_directory -o output_file #------------------------------------------------------------------------------ require 'find' require 'fileutils' require 'getoptlong' def usage puts "usage: parse_sam_farm_logs -d dirname -o output_file" exit(-1) end usage if ARGV.length < 0 opts = GetoptLong.new( [ "--directory" , "-d", GetoptLong::REQUIRED_ARGUMENT ], [ "--output" , "-o", GetoptLong::REQUIRED_ARGUMENT ], [ "--stream" , "-s", GetoptLong::REQUIRED_ARGUMENT ], [ "--unzip" , "-u", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose" , "-v", GetoptLong::NO_ARGUMENT ] ) $work_dir = `pwd`.strip $stream = "zzzzzz"; $directory = "./" $verbose = 0; $unzip = 0; $script = $work_dir+"/cdfopr/OfflineMon/scripts/parse_sam_farm_production_log.awk" ; $output_file=""; #----------------------------- process the parsed options opts.each do |opt, arg| if (opt == "--directory" ) ; $directory = arg elsif (opt == "--output" ) ; $output_file = arg elsif (opt == "--stream" ) ; $stream = arg elsif (opt == "--unzip" ) ; $unzip = arg.int elsif (opt == "--verbose" ) ; $verbose = 1 end if ($verbose != 0) ; puts "Option: #{opt}, arg #{arg.inspect}" ; end end #------------------------------------------------------------------------------ # all the files in the input directory are supposed to be the logfiles #------------------------------------------------------------------------------ list = Dir.entries($directory); if ( $output_file != "" ) rc=`if [ -f #{$output_file} ] ; then rm #{$output_file} ; fi ; touch #{$output_file}` end list.each { |file| # fn = file.split("/").last; if ((file != ".") && ( file != "..")) full_name=$directory+"/"+file; puts "#{full_name} #{File.size(full_name)}"; if ($unzip != 0) cmd = "gzip -d -c " + full_name + " | " + $script ; else cmd = "cat " + full_name + " | " + $script ; end if ( $output_file != "") ; cmd = cmd + " >> " + $output_file; end rc=`#{cmd}` end }