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
1 changed files with 20 additions and 5 deletions

View File

@ -25,23 +25,38 @@
[ $# -ge 1 ] || __cdist_usage "[-p] <target host> [target host ]" [ $# -ge 1 ] || __cdist_usage "[-p] <target host> [target host ]"
set -eu set -eu
filter()
{
awk -v host=$1 '{ print "[" host "] " $0 }'
}
parallel="" parallel=""
if [ "$1" = "-p" ]; then if [ "$1" = "-p" ]; then
parallel=yes parallel=yes
shift shift
fi fi
i=0
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
# always assume we run parallel if [ "$parallel" ]; then
cdist-deploy-to "$1" | awk -v host=$1 '{ print "[" host "] " $0 }' & cdist-deploy-to "$1" | filter
shift # 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_ shift
[ "$parallel" ] || wait
done done
# else wait after all are started # else wait after all are started
if [ "$parallel" ]; then if [ "$parallel" ]; then
__cdist_echo info "Waiting for cdist-deploy-to jobs to finish" __cdist_echo info "Waiting for cdist-deploy-to jobs to finish"
while [ $i -gt 0 ]; do
done
wait wait
fi fi