begin new error catching code and make filter a function

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-04-16 23:51:24 +02:00
parent 24428b2070
commit da1d3fbc04

View file

@ -25,23 +25,38 @@
[ $# -ge 1 ] || __cdist_usage "[-p] <target host> [target host ]"
set -eu
filter()
{
awk -v host=$1 '{ print "[" host "] " $0 }'
}
parallel=""
if [ "$1" = "-p" ]; then
parallel=yes
shift
fi
i=0
while [ $# -ge 1 ]; do
# always assume we run parallel
cdist-deploy-to "$1" | awk -v host=$1 '{ print "[" host "] " $0 }' &
shift
if [ "$parallel" ]; then
cdist-deploy-to "$1" | filter
# Record pid and host for use later
eval pid_$i=$!
eval host_$i=\$1
i=$((i+1))
else
cdist-deploy-to "$1" | filter
fi
# if not, wait for it _now_
[ "$parallel" ] || wait
shift
done
# else wait after all are started
if [ "$parallel" ]; then
__cdist_echo info "Waiting for cdist-deploy-to jobs to finish"
while [ $i -gt 0 ]; do
done
wait
fi