#! /bin/bash usage () { cat< Number of jobs to submit -f, --first First task-id for job to submit -s, --stamp Batch stamp to use [ default: current time] -e, --exists Specify what action should be taken if the output directory already exists. -o, --output Ouptut directory [ default: \$ICEDUST_LOCAL_STORAGE/ ] -Q, --qsub-options Specify additional options for qsub, eg. "-q hepmedium.q" -I, --icedust-options Specify additional options for the RunIcedustControl command, eg "-t ~/myTmp" -i, --inputfiles A (unexpanded) wild-carding to provide input files. Make sure to escape any wild-carding and white-space in the filenames. EOF exit $1 } CommandLine="$@" VERBOSE=1 VERBOSE_STREAM=/dev/stderr DEBUG_STREAM=/dev/null NoPrimaries=100 FirstJob=1 NoJobs=10 RunStamp=`date +%y%m%d-%H%M` OutputDir=$ICEDUST_LOCAL_STORAGE QsubOptions="" IcedOptions="" InputFiles="" IfExists="fail" Debug=false while [ "$#" != 0 ]; do case "$1" in -h | --help ) usage 0;; -d | --debug ) shift;Debug=true; set -x; DEBUG_STREAM=/dev/stderr ;; -f | --first ) shift; FirstJob="$1" ; shift;; -n | --jobs ) shift; NoJobs="$1" ; shift;; -s | --stamp ) shift; RunStamp="$1" ; shift;; -o | --out-dir ) shift; OutputDir="$1" ; shift;; -i | --inputfiles ) shift; InputFiles="$1" ; shift;; -e | --exists ) shift; IfExists="`tr 'A-Z' 'a-z' <<<"$1"`" ; shift;; -Q | --qsub-options ) shift; QsubOptions="$QsubOptions $1" ; shift;; -I | --icedust-options ) shift; IcedOptions="$IcedOptions $1" ; shift;; -*) echo Unknown option $1 ; usage 1 ;; *) ConfigFile=$1; shift || true;; esac done OutputDir="$OutputDir/$RunStamp" if [ -z "$ICEDUST_HOME" ];then echo Error: Missing ICEDUST_HOME variable echo " Please setup ICEDUST by sourcing the appropriate setup.sh file" echo usage 1 elif [ -z "$ConfigFile" ];then echo Error: I need the name of a config to run with echo usage 1 elif [ ! -r "$ConfigFile" ];then echo Error: Cannot find input config file: "'$ConfigFile'" exit 1 elif [ ! "$IfExists" == fail ] \ && [ ! "$IfExists" == append ] \ && [ ! "$IfExists" == recreate ] ;then echo "Error: Bad option given to `-e, --exists` option: '$IfExists'" echo " Should be one of: FAIL, APPEND, RECREATE" exit 1 fi # Handle existing output directories AppendVal="" if [[ "$OutputDir/*" != `echo "$OutputDir/"*` ]];then if [ "$IfExists" == fail ]; then echo "Error: Output directory: '$OutputDir' already exists!" exit 1 elif [ "$IfExists" == recreate ]; then rm -rf "$OutputDir" elif [ "$IfExists" == append ]; then AppendVal=2 while [ -e "$OutputDir/BatchConfig-$AppendVal" ];do AppendVal=$((AppendVal+1)) done AppendVal=-"$AppendVal" fi fi # Setup all the filename variables BatchConfig="$OutputDir/BatchConfig$AppendVal" RunBatch="$OutputDir/RunBatch$AppendVal.sh" ActualConfig="`basename "$ConfigFile"|cut -f1 -d. `$AppendVal".cfg InputFileList="$OutputDir/InputFiles" # Prepare the output directory mkdir -p "$OutputDir/"{batch_output,output,{timers,configs}/$AppendVal} cp "$ConfigFile" "$OutputDir/$ActualConfig" # Sort out the input file list touch "$InputFileList" if [ -n "${InputFiles}" ];then [ "${InputFiles:0:1}" != '/' ] && InputFiles="`pwd`/$InputFiles" ls $InputFiles > "$InputFileList" fi cat < "$RunBatch" <> $RunBatch<<"EOF" cat "$SetupFile" . "$SetupFile" echo "Disk Usage Before running:" df -lh [ -z "$SGE_TASK_ID" ] && export SGE_TASK_ID=1 TaskId=${SGE_TASK_ID} PaddedId=`printf "%03d" ${TaskId}` export INPUT_FILE="" export OUTPUT_DIR="${OutputDir}/output" date +"%y%m%d-%H:%M:%S:%N" > "$OutputDir/timers/$AppendVal/${PaddedId}.start" if [ "$TaskId" -gt ${NumInputFiles} ] ;then if [ ${NumInputFiles} -gt 0 ] ;then echo "FATAL ERROR: No more input files ( File index: $TaskId )" echo " Input files: " cat "$InputFileList" exit 1 fi else INPUT_FILE="`head -${TaskId} "${InputFileList}" |tail -1`" INPUT_FILE="`readlink -f "${INPUT_FILE}"`" fi export INPUT_FILE_LIST="${InputFileList}" printenv time RunIcedustControl -c "$OutputDir/$ConfigFile" date +"%y%m%d-%H:%M:%S:%N" > "$OutputDir/timers/$AppendVal/${PaddedId}.stop" echo "Disk Usage After running:" df -lh ls -ltrh $TMPDIR EOF Jobname="`cut -f1 -d. <<<"$ActualConfig"`" CMD='qsub '"$QsubOptions"' -N "$Jobname" -t "$FirstJob"-"$NoJobs" -e "$OutputDir/batch_output" -o "$OutputDir/batch_output" "$RunBatch"' echo ${CMD} echo -n "qsub response: " >>"$BatchConfig" eval $CMD |tee -a "$BatchConfig"