#!/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/scripts/concatenate.rb -d -p 2004_08 -s 11:30 #------------------------------------------------------------------------------ require 'find' require 'fileutils' require 'getoptlong' def usage puts "usage: concatenate.rb dirname pattern s1 s2 [debug]" exit(-1) end usage if ARGV.length < 1 opts = GetoptLong.new( [ "--book" , "-b", GetoptLong::REQUIRED_ARGUMENT ], [ "--dataset" , "-d", GetoptLong::REQUIRED_ARGUMENT ], [ "--host" , "-h", GetoptLong::REQUIRED_ARGUMENT ], [ "--input_tcl_dir" , "-i", GetoptLong::REQUIRED_ARGUMENT ], [ "--segments" , "-s", GetoptLong::REQUIRED_ARGUMENT ], [ "--output_dir" , "-o", GetoptLong::REQUIRED_ARGUMENT ], [ "--pattern" , "-p", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose" , "-v", GetoptLong::NO_ARGUMENT ] ) $hostname=`hostname -f` $dataset="" $book="cdfpewk" $pattern="2004" $smin=0 $smax=0 $verbose=0; $input_tcl_dir = "" #----------------------------- process the parsed options opts.each do |opt, arg| if (opt == "--dataset" ) ; $dataset = arg elsif (opt == "--book" ) ; $book = arg elsif (opt == "--host" ) ; $host = arg elsif (opt == "--pattern" ) ; $pattern = arg elsif (opt == "--verbose" ) ; $verbose = 1 elsif (opt == "--input_dir" ) ; $input_tcl_dir = arg elsif (opt == "--output_dir" ) ; $output_dir = arg elsif (opt == "--segments" ) $smin = arg.split(":")[0].to_i; $smax = arg.split(":")[1].to_i; end if ($verbose != 0) ; puts "Option: #{opt}, arg #{arg.inspect}" ; end end if ($input_tcl_dir == "") $input_tcl_dir="/cdf/opr2/cdfopr/datasets/#{$book}/#{$dataset}/requests" end pwd=`pwd`.sub("\n","") puts $input_tcl_dir puts "smin = #{$smin} smax = #{$smax}" #----------------------------------------------------------------------- # get list of request files, syntax (example): pattern.017 #----------------------------------------------------------------------- list = Dir.entries($input_tcl_dir); list.each { |file| fn = file.split("/").last; puts "#{fn} #{fn.index($pattern).to_i}" if fn.index($pattern) == 0 #----------------------------------------------------------------------- # time to submit the job #----------------------------------------------------------------------- ok = 1; if $smin > 0 ; # test job number request_number = fn.split(".").last.to_i if ( request_number < $smin) || (request_number > $smax) ok = 0 end end puts " fn = #{fn} ok = #{ok}" if ok != 0 script=pwd + "/cdfopr/scripts/process_concatenation_request" puts "executing: #{script} #{$input_tcl_dir}/#{file}" rc=`#{script} #{$input_tcl_dir}/#{file}` end end }