diff 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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lemuriformes/waiter.sh	Sun Dec 10 17:42:52 2017 -0800
@@ -0,0 +1,27 @@
+#!/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