Created
November 6, 2018 14:31
-
-
Save leifdenby/cf68f673a158b924443f09f9bdadebb6 to your computer and use it in GitHub Desktop.
Utility for chaining multiple dependent PBS submit scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Utility function for chaining multiple PBS submit scripts | |
# Leif Denby 6/11/2018 | |
# | |
# usage: | |
# | |
# 1. Create a file containing the individual steps, e.g. | |
# | |
# tasklist.sh: | |
# WALLCLOCK=00:15:00 ./run.sh example_run | |
# WALLCLOCK=00:15:00 ./run.sh analysis | |
# | |
# 2. Pipe this list to taskchain.sh or provide with tasklist as first argument | |
# | |
# > cat tasklist.sh | taskchain.sh | |
# | |
# or | |
# | |
# > taskchain.sh tasklist.sh | |
# | |
# Each task will the have the JOB id of the previous task provided through the | |
# environment variables DEPENDSON. This is extracted as the first line of | |
# output returned from each task command (e.g. what PBS returns when `qsub` is | |
# invoked) | |
# | |
# | |
# For the above example the dummy script run.sh below can be used to see the | |
# behaviour | |
# | |
# run.sh: | |
# echo "42424.job" | |
# echo "Simulating PBS job: $@" | |
# | |
# echo "wc=${WALLCLOCK}" | |
# echo "do=${DEPENDSON}" | |
# https://stackoverflow.com/a/17841619 | |
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; } | |
lines=() | |
while read line | |
do | |
lines+=("$line") | |
done < "${1:-/dev/stdin}" | |
TASKLIST=$(join_by $'\n' "${lines[@]}") | |
echo "Received task list:" | |
echo "${TASKLIST}" | |
echo "" | |
N_LEFT=$(echo "`echo "${TASKLIST}" | wc -l` - 1" | bc) | |
NEXTTASK=`echo "${TASKLIST}" | head -n1` | |
TASKLIST=`echo "${TASKLIST}" | tail -n+2` | |
JOBID="" | |
while [ "${NEXTTASK}" != "" ]; do | |
echo "taskchain> queuing '${NEXTTASK}', ${N_LEFT} tasks left" | |
JOBID=$(eval "DEPENDSON=${JOBID} ${NEXTTASK}") | |
echo "taskchain> queued as ${JOBID}" | |
JOBID=$(echo "${JOBID}" | head -n1) | |
echo "" | |
NEXTTASK=`echo "${TASKLIST}" | head -n1` | |
TASKLIST=`echo "${TASKLIST}" | tail -n+2` | |
N_LEFT=$(echo "`echo "${TASKLIST}" | wc -l` - 1" | bc) | |
done | |
echo "taskchain> all tasks completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment