From: Mark Wooding Date: Sat, 9 Jul 2011 12:32:39 +0000 (+0100) Subject: hacks/ssh: Redirect the master's output and error. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/e41b452fce323a3f84907a48a7d2680dbbfe1475 hacks/ssh: Redirect the master's output and error. Otherwise it inherits our streams, and something waiting from EOF from us will become seriously disappointed. It's not like the master has anything especially interesting to say on stdout anyway. The error stream is captured into a logfile for later perusal. Just stdout wasn't enough. --- diff --git a/hacks/ssh b/hacks/ssh index a11c777..16b7578 100755 --- a/hacks/ssh +++ b/hacks/ssh @@ -25,6 +25,8 @@ ### Configuration. : ${REAL_SSH=/usr/bin/ssh} +: ${SSH_HOME=$(unset HOME; bash -c 'echo ~/.ssh')} +: ${SSH_LOGDIR=$SSH_HOME/log-$(hostname)} ###-------------------------------------------------------------------------- ### Parse the command line and dredge out information. @@ -113,6 +115,13 @@ while :; do login=$arg ;; + ## Catch the port number. We want this for building the logfile + ## name. + ?,p*) + masteropts=("${masteropts[@]}" "-p$arg") + port=$arg + ;; + ## These options are interesting to the master connection. m,[aADLlRSwxXv]*) masteropts=("${masteropts[@]}" "-${o:0:1}$arg") @@ -162,8 +171,11 @@ case "$mode" in exec "$REAL_SSH" "${opts[@]}" ${host+"$host"} "$@" ;; m) + mkdir -p -m700 "$SSH_LOGDIR" + logfile=$SSH_LOGDIR/${login+"$login@"}"$host"${port+":$port"}.log if ! "$REAL_SSH" -Ocheck ${login+"$login@"}"$host" >/dev/null 2>&1; then - "$REAL_SSH" -MNf "${masteropts[@]}" "$host" + "$REAL_SSH" -MNf "${masteropts[@]}" "$host" \ + /dev/null 2>$logfile fi exec "$REAL_SSH" ${opts[@]} "$host" "$@" ;;