From 568aefc98e7ec7b5bab8d09f3b560c72d4d6066a Mon Sep 17 00:00:00 2001 From: Jim Pannacciulli Date: Thu, 23 Jul 2015 14:01:35 -0700 Subject: Add '-C' option to include remote command / metadata in output --- pars.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pars.sh b/pars.sh index 02d1c01..597de31 100644 --- a/pars.sh +++ b/pars.sh @@ -46,6 +46,9 @@ parssh () { local _parssh_ssh_config="$2" shift ;; + C|-savecmd) + local _parssh_savecmd="true" + ;; h|-help) _parssh.usage return $? @@ -99,14 +102,25 @@ parssh () { exec 9<"$_parssh_servers" } - while read host; do - while (( $(jobs -pr | wc -l) >= ${_parssh_concurrency:-4} )); do - sleep 1 - done - $_parssh_ssh "$@" 2> >(_parssh.host_prepend >&2) |\ - _parssh.host_prepend & - done <&9 2> >($_parssh_outfun err >&2) |\ - $_parssh_outfun out + { + [[ "$_parssh_savecmd" == "true" ]] && { + printf "### ###\n" + printf "### %s: %s\n"\ + date "$(date +%F@%R%z)"\ + user "$USER($UID)"\ + pwd "$PWD" + printf "### BEGIN parssh remote commands ###\n" + printf "%s\n### END parssh remote commands ###\n### ###\n"\ + "$@" + } + while read host; do + while (( $(jobs -pr | wc -l) >= ${_parssh_concurrency:-4} )); do + sleep 1 + done + $_parssh_ssh "$@" 2> >(_parssh.host_prepend >&2) |\ + _parssh.host_prepend & + done <&9 2> >($_parssh_outfun err >&2) + } | $_parssh_outfun out wait -- cgit v1.2.3