#! /bin/bash ## By Julen Larrucea VERSION=1.0 PWD=$(pwd -P ) COUNT="1" LASTJOB="3" SCRIPTNAME="job.cmd" while getopts n:f:v opt do case "$opt" in n) LASTJOB=$OPTARG;; f) SCRIPTNAME=$OPTARG;; v) echo "resend version " $VERSION; exit 1;; \?) echo """ resend usage: -n Total number of jobs to send -f File name of the batch script (def. job.cmd) -v Print version -h print this help Example: nohup resend -n 5 -f /path/to/script.cmd & Tip: touch STOP stops the loop """ exit 1 ;; esac done while [ $COUNT -le $LASTJOB ] do if [ ! -f "STOP" ]; then JOBLIST="" for JOB in $(for i in `qstat -u $USER |grep $USER |awk '{print $1}' ` ; do qstat -j $i |grep "sg e_o_workdir:" | awk '{print $2}' ; done) # if "now is not available" do JOBLIST=$JOBLIST" "$JOB done if [[ $JOBLIST =~ $PWD ]]; then #echo "waiting 1m" sleep 1m else echo "submitting" $COUNT qsub $SCRIPTNAME COUNT=$[$COUNT+1] fi sleep 5s else rm STOP exit 1 fi done