Skip to content

Instantly share code, notes, and snippets.

@olegs
Last active May 11, 2017 14:17
Show Gist options
  • Save olegs/563c9a17aa35d8625242cd1e7879233f to your computer and use it in GitHub Desktop.
Save olegs/563c9a17aa35d8625242cd1e7879233f to your computer and use it in GitHub Desktop.
Code to wait for the asynchronous tasks to finish on Portable Batch System using qsub
# Small procedure to wait until all the tasks are finished on the qsub cluster
# Example of usage: wait_complete $TASKS, where $TASKS is a task ids returned by qsub.
wait_complete()
{
echo "Waiting for tasks..."
for TASK in $@
do :
echo -n "TASK: $TASK"
# The task id is actually the first numbers in the string
TASK_ID=$(echo ${TASK} | sed -e "s/\([0-9]*\).*/\1/")
if [ ! -z "$TASK_ID" ]; then
while qstat ${TASK_ID} &> /dev/null; do
echo -n "."
sleep 100
done;
fi
echo
done
echo "Done."
}
@olegs
Copy link
Author

olegs commented May 11, 2017

The same code using checkjob instead of qstat is the following:

# Small procedure to wait until all the tasks are finished on the qsub cluster
# Example of usage: wait_complete $TASKS, where $TASKS is a task ids returned by qsub.
wait_complete()
{
    echo "Waiting for tasks..."
    # Sleep 1 minute to wait until checkjob command would be able to process just submitted tasks
    sleep 1m

    for TASK in $@
    do :
        echo -n "TASK: $TASK"
        # The task id is actually the first numbers in the string
        TASK_ID=$(echo ${TASK} | sed -e "s/\([0-9]*\).*/\1/")
        if [ ! -z "$TASK_ID" ]; then
            while checkjob ${TASK_ID} &> /dev/null; do
                echo -n "."
                sleep 100
            done;
        fi
        echo
    done
    echo "Done."
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment