A bash script that allows qsub on TORQUE to wait for the job to complete, which is very similar to -sync y on an SGE system

I am using a cluster with Torque / Maui system. I have a bash script that send one job with the qsub command and then perform several actions, for example, move files, write ASCII files and check the result of the work that I sent. As for this result, basically, if it contains number 1, you need to send the task again. If different from 1, the bash script does something else.

The problem is that qsub is running in the background and all bash are evaluated right away. I would like to make qsub behave the same as awk, cat, sort, etc. When the script just goes further after completing these commands - if not put in the background.

So, I need bash to stop in the first qsub and continue working immediately after qsub completes, which means that when the work finishes. Is there any way to do this? It will be something similar to:

   -sync y    # in the SGE system, for instance.

what i have:

#!/bin/bash
.
.
some commands
.
.
qsub my_application  # need to wait until my_application get done
.
.
more commands
.
.
my_application_output=(`cat my_application_output.txt`)

case "$my_application_output" in
["1"])
     qsub my_application
     ;;
["0"])
     some commands
     ;;
["100"])
     some commands
     ;;
*)
     some commands
     exit 1

esac

.
.

some comments


  • It is not convenient to use: qsub -Ix, as soon as I want to save the output in the output file; and don’t want to block node by running interactive mode (-I)
  • I assume that this is not a simple work-dependent problem, as soon as a re-presentation of 1) can happen, 2) cannot, and most importantly, if this happens (1), it can be several times.

thanks for all

+4
source share
3 answers

Quim Oct 3 at 4:05: "This is not a simple work dependency problem"

- script . script my_application_output.txt, sleep ? -

#!/usr/bin/env bash
# I prefer to have constants at the top
my_application_output_fp='/path/to/my_application_output.txt' 
#
#
# some commands
#
#
qsub my_application
#
#
# more commands
#
#

# sleep until my_application outputs
while [[ ! -r "${my_application_output_fp}" ]] ; do
    sleep 1
done

my_application_output="$(cat ${my_application_output_fp})"
# process it

my_application_output.txt my_application, my_application, , :

#!/usr/bin/env bash
my_application_flag_fp='/path/to/my_application_flag.txt' 
my_application_output_fp='/path/to/my_application_output.txt' 
#
#
# some commands
#
#
qsub my_application
#
#
# more commands
#
#

# sleep until my_application writes flag
while [[ ! -r "${my_application_flag_fp}" ]] ; do
    sleep 1
done

if [[ ! -r "${my_application_output_fp}" ]] ; then
    # handle error
fi
# else
my_application_output="$(cat ${my_application_output_fp})"
# process it
+2

qsub , -

$qsub myapplication  
12345.hpc.host

qstat,

$qstat 12345.hpc.host
Job ID                    Name             User            Time Use S Queue
------------------------- ---------------- --------------- -------- - -----
12345.hpc.host            STDIN            user            00:00:00 Q queue

, qstat.

$qstat 12345.hpc.host
qstat: Unknown Job Id Error 12345.hpc.host

, . /dev/null qstat,

if qstat 12345.hpc.host &>/dev/null; then
    echo "Job is running"
else
    echo "Job is not running"
fi

,

qstat 12345.hpc.host &> /dev/null && echo "Job is running" || echo "Job is NOT running"

, , . , id , qstat ,

JOBID=$(qsub myapplication)
while qstat $JOBID &> /dev/null; do
    sleep 5;
done;

while bash . , , .

+2

qsub:

-sync y qsub            .

0

All Articles