Improve turbine-output-search
# Turbine Output Search
# for JOB_ID in TURBINE_OUTPUT_ROOT
-set -e
-
+set -eu
THIS=$( cd $( dirname $0 ) ; /bin/pwd )
TURBINE_HOME=$( cd ${THIS}/../.. ; /bin/pwd )
source ${TURBINE_HOME}/scripts/helpers.zsh
+# If non-empty, look for multiple matches
+M=""
+zparseopts -D m=M
+
usage()
{
- print "usage: turbine-output-search.zsh <JOB_ID>"
+ print "usage: turbine-output-search.zsh [-m] <JOB_ID>"
+ print "produces 1 match, or multiple if given -m"
}
if [[ ${#} != 1 ]]
@@ -35,22 +39,24 @@ fi
JOB_ID=$1
-checkvar JOB_ID
-
TURBINE_OUTPUT_ROOT=${TURBINE_OUTPUT_ROOT:-${HOME}/turbine-output}
-set -u
-
-find ${TURBINE_OUTPUT_ROOT} -name jobid.txt | \
+FOUND=0
+# find -H : Allows for TURBINE_OUTPUT_ROOT to be a symlink
+find -H ${TURBINE_OUTPUT_ROOT} -name jobid.txt | \
while read ID_FILE
do
ID=$( < ${ID_FILE} )
- if [[ ${JOB_ID} == ${ID}* ]]
+ if [[ ${ID} == ${JOB_ID}* ]]
then
print TO=${ID_FILE:h}
- exit 0
+ (( ! ${#M} )) && exit 0
+ FOUND=1
fi
done
+if (( ! FOUND )) {
# We didn't find anything
-exit 1
+ return 1
+}
+return 0
