view lemuriformes/waiter.sh @ 17:4793f99b73e0

[lemuriformes] utility functions
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 17:42:52 -0800
parents
children
line wrap: on
line source

#!/bin/bash

# parallelize and wait for a set of jobs;
# it's MapReduce for `bash`!

FAIL=0

# See http://jeremy.zawodny.com/blog/archives/010717.html

{{for command in commands}}
{{command}} &
{{endfor}}

# wait for processes
for job in `jobs -p`
do
    echo ${job}
    wait ${job} || let "FAIL+=1"
done

if [ "${FAIL}" == "0" ]
then
    exit 0
fi

echo "${FAIL} failing job(s)"
exit 1