summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-04-09 18:18:28 +0200
committerErich Eckner <git@eckner.net>2016-04-09 18:18:28 +0200
commit55823096510f4c308f08aaca133e1f7ae335b61b (patch)
treeb9752df89a94bfc6eb99931a691200b72ce11a47
downloadrunjobsparallel-55823096510f4c308f08aaca133e1f7ae335b61b.tar.xz
initial commit: sollte funktionierenv0.0
-rwxr-xr-xrunjobsparallel50
1 files changed, 50 insertions, 0 deletions
diff --git a/runjobsparallel b/runjobsparallel
new file mode 100755
index 0000000..763d301
--- /dev/null
+++ b/runjobsparallel
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# /usr/sbin/runjobsparallel: run all executables in specified directory parallel
+#
+
+if [ "$1" = "" ]; then
+ echo "usage: $0 <dir>"
+ exit 1
+fi
+
+cd $1 || exit 1
+
+tmpDir=$(mktemp -d /tmp/runjobsparallel.XXXXXX)
+
+for file in ./*; do
+ if [ -f $file ] && [ -x $file ]; then
+ i=${#errFiles[@]}
+ errFiles[${i}]="${tmpDir}/err.${i}"
+ (nice -n 19 $file; echo $? > ${errFiles[${i}]})&
+ pids[${i}]=$!
+ fi
+done
+
+allesDa=false
+while ! ${allesDa}
+do
+ sleep 1
+ allesDa=true
+ maxErr=0
+ for ((i=0; i<${#errFiles[@]}; i++))
+ do
+ if [ -r ${errFiles[${i}]} ]
+ then
+ curErr=$(cat "${errFiles[${i}]}")
+ [ ${curErr} -gt ${maxErr} ] && maxErr=${curErr}
+ elif ps aux | awk '{print $2}' | grep -q "^${pids[${i}]}\$"
+ then
+ allesDa=false
+ else
+ echo 255 > "${errFiles[${i}]}"
+ maxErr=255
+ fi
+ done
+done
+
+rm -rf ${tmpDir}
+
+exit ${maxErr}
+
+# End of file