From eb76f99f7011edcaf33795b32b0e9cd6f5b8db1c Mon Sep 17 00:00:00 2001 From: James Pannacciulli Date: Tue, 27 Jan 2015 10:39:07 -0800 Subject: Add prepend_host flag so we can know which output came from which host also consolidate shifts in option-parsing case loop --- pars.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pars.sh b/pars.sh index 819153b..f6741b7 100644 --- a/pars.sh +++ b/pars.sh @@ -8,7 +8,6 @@ parssh () { [0-9]*) [[ "${1#-}" != *[^0-9]* ]] && { local parssh_concurrency=${1#-} - shift } ;; fo|fouter) @@ -18,7 +17,6 @@ parssh () { } local parssh_fouter="$2" shift - shift ;; fi|finner) [[ -r "$2" ]] || { @@ -27,9 +25,12 @@ parssh () { } local parssh_finner="$2" shift - shift + ;; + p|prepend_host) + local parssh_prepend_host=true ;; esac + shift done [[ -z "$parssh_fouter" ]] && { @@ -43,12 +44,17 @@ parssh () { sleep 1 done if [[ -z "$parssh_finner" ]]; then - ssh -no StrictHostKeyChecking=no $host "$@" & + ssh -no StrictHostKeyChecking=no $host "$@" | host_prepend & else - ssh -To StrictHostKeyChecking=no $host "$@" < "$parssh_finner" & + ssh -To StrictHostKeyChecking=no $host "$@" < "$parssh_finner" | host_prepend & fi done <&9 wait exec 9>&- [[ "${origopts//[^m]/}" == "m" ]] || set +m } + +host_prepend () + while read -r; do + printf "${parssh_prepend_host+$host: }%s\n" "$REPLY" + done -- cgit v1.2.3