diff options
-rwxr-xr-x | runjobsparallel | 50 |
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 |