#!/bin/sh version="Queue v0.1 Copyright (C) 1994 Karl J. Runge"; # Queue: Script to take batchqueue command with flags to be run, create a # script file, submit job, watch for finished file flag, clean up, then exit. # # Usage: # Queue [-debug] [-s delay] [-mail [user --]] [-help] [-norc] [-eof] \ # [-show] [-cmd queue_cmd] [-f queue_flag ] [-i insert] [-del patt] \ # [-rc file] [-v version] command # examples: # Queue -cmd qsub -f "-q small" a.out \< infile \> outfile # Queue -s 5 -mail -cmd "at.pl -s 10" "ls -l | wc -l > gat ; ls -l >> gat" # Options: # -debug: print out info that would be used but do not submit job. # -show: print out info and prompt whether to submit it or not. # -s delay: set time to sleep between checks for signal file (space reqd). # -mail -m: mail the user after job has finished. # use "-m user@host --" to specify to mail to other than $USER # -cmd q_cmd: the job submission command (e.g. "at" or "qsub" or "llsubmit"). # -f q_flag: flag(s) for command q_cmd (can be included in -cmd if you like) # -norc: do not add lines from Queuerc file to Script. # -rc file: use "file" instead of standard Queuerc file(s). # -del patt: delete lines matching pattern from Queuerc file # -i insert: insert the line(s) to the command script. # -eof: append EOF to end of script. Also done if Queuerc contains EOF # -help: print out this information. # # command: desired command, with protected >, <, |, and ; # NOTE: -rc -del -i flags are interpreted in the order they appear. # # Lines from the file $HOME/.Queuerc ./Queuerc or ./.Queuerc will be added to # Script automatically (the first one found in the above order). # if Queuerc file contains cd "`pwd`" it is subbed before placing into Script # "" "" `SCRIPT` or `FLAG` it is $SCRIPT or $FLAG value is substituted # Queuerc file can contain lines '#Q QUEUE qsub' or '#Q SLEEP 30' to set those # variables. (they are overidden by command line flags -cmd or -s) QUEUE="llsubmit "; # batch submit command | CHANGE TO LOCAL CASE SLEEP="10"; # sleep interval | or overide in Queuerc helpline="41"; QUEUE_ON=""; SLEEP_ON=""; DEBUG=""; NORC=""; EOF=""; SHOW=""; MAILIT=""; MAILTO=""; QueueOpts=""; QueueRC="$HOME/.Queuerc"; SCRIPT="QueueTmp$$"; # tmp file for script FLAG="QueueFlag$$"; # tmp file for signal file QueueRC1="Queue1RC$$"; # tmp file for .Queuerc work QueueRC2="Queue2RC$$"; # tmp file for .Queuerc work if [ -f "$HOME/.Queuerc" ]; then QueueRC="$HOME/.Queuerc"; cat $QueueRC > $QueueRC1; elif [ -f "./Queuerc" ]; then QueueRC="./Queuerc"; cat $QueueRC > $QueueRC1; elif [ -f "./.Queuerc" ]; then QueueRC="./.Queuerc"; cat $QueueRC > $QueueRC1; fi cleanRC () { rm -f $QueueRC1 $QueueRC2; } BREAK=""; while [ 1 ] do case $1 in "-debug") DEBUG="True"; ;; "-eof") EOF="True"; ;; "-show") SHOW="True"; ;; "-s") shift; SLEEP="$1"; SLEEP_ON='True'; ;; "-s"*) echo; cleanRC; head -$helpline $0 | more; exit 1;# bail on -s5 ;; "-m"|"-mail") MAILIT="True"; case $3 in "--") MAILTO="$2"; shift; shift; ;; esac ;; "-norc") NORC="True"; ;; "-rc") shift; if [ -f "$1" ]; then QueueRC="$1"; cat $QueueRC > $QueueRC1; elif [ -f "$HOME/$1" ]; then QueueRC="$HOME/$1"; cat $QueueRC > $QueueRC1; else echo "$0: no such file $1"; fi ;; "-i") shift; echo "$1" >> $QueueRC1; ;; "-del") shift; grep -v -e "$1" $QueueRC1 > $QueueRC2; cp $QueueRC2 $QueueRC1; ;; "-v"*) echo; cleanRC; echo "$version"; echo; exit 0; ;; "-h"*) echo; cleanRC; head -$helpline $0 | more; exit 0; ;; "-cmd") shift; QUEUE="$1"; QUEUE_ON='True'; ;; "-f") shift; QueueOpts="$1"; ;; "-"*) case $1 in "-i") BREAK="True"; ;; *) echo; head -$helpline $0; echo; echo "$1 not an option, Bye!"; cleanRC; exit 1; ;; esac ;; *) BREAK="True"; ;; esac if [ "$BREAK" = "True" ]; then break; fi shift; done echo '#!/bin/sh' > $SCRIPT; # start making batch script if [ -f "$QueueRC1" ] && [ "$NORC" != "True" ]; then # add lines from ~/.Queuerc if [ "$QUEUE_ON" = "" ]; then # check Queuerc for "#Q QUEUE switch Test="`grep -i '#Q *QUEUE' $QueueRC1 | awk '{print $3}'`"; if [ "$Test" != "" ]; then QUEUE="$Test"; fi fi if [ "$SLEEP_ON" = "" ]; then # check Queuerc for "#Q SLEEP switch Test="`grep -i '#Q *SLEEP' $QueueRC1 | awk '{print $3}'`"; if [ "$Test" != "" ]; then SLEEP="$Test"; fi fi if [ "$EOF" = "" ]; then if [ "`grep EOF $QueueRC1`" != "" ]; then EOF="True"; fi fi Pwd="`pwd`"; PwdX="`type Pwd 2>&1 | grep 'not found'`"; # echo "PwdX= $PwdX" # yes, messy isn't it # I wanted to avoid eval if [ "$PwdX" ]; then # echo "NoHave Pwd"; exit; cat $QueueRC1 | sed -e s:cd\ \"\`pwd\`\":cd\ \"$Pwd\": | sed -e s:\`SCRIPT\`:$SCRIPT: | sed -e s:\`FLAG\`:$FLAG: >> $SCRIPT; else # echo "Have Pwd"; exit; PwdY="`Pwd`"; cat $QueueRC1 | sed -e s:cd\ \"\`pwd\`\":cd\ \"$Pwd\": | sed -e s:\`Pwd\`:"$PwdY": | sed -e s:\`SCRIPT\`:$SCRIPT: | sed -e s:\`FLAG\`:$FLAG: >> $SCRIPT; fi fi cleanRC; echo "$*" >> $SCRIPT; # put in actual command echo "touch $FLAG" >> $SCRIPT; # signal for finished job if [ "$EOF" ]; then echo "EOF" >> $SCRIPT; # Script wrapped with <