X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/4d7d040beb835fa5ea0015d0e1202f61fa79c0c1..c3ee31b9820d8466267a73ab1ad652e043e31314:/hacks/ssh diff --git a/hacks/ssh b/hacks/ssh index a11c777..cbec247 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,8 +115,15 @@ 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]*) + m,[aADLlRSwxXv46]*) masteropts=("${masteropts[@]}" "-${o:0:1}$arg") ;; @@ -137,7 +146,7 @@ while :; do ## A bare word. Maybe it's the hostname, or the start of the command. *) - case ${host-t} in + case ${host-t}${host+nil} in t) host=$1 ;; *) break ;; esac @@ -162,8 +171,14 @@ case "$mode" in exec "$REAL_SSH" "${opts[@]}" ${host+"$host"} "$@" ;; m) - if ! "$REAL_SSH" -Ocheck ${login+"$login@"}"$host" >/dev/null 2>&1; then - "$REAL_SSH" -MNf "${masteropts[@]}" "$host" + mkdir -p -m700 "$SSH_LOGDIR" + logfile=$SSH_LOGDIR/${login+"$login@"}"$host"${port+":$port"}.log + if ! "$REAL_SSH" -Ocheck \ + ${port+-p$port} ${login+"$login@"}"$host" \ + >/dev/null 2>&1 + then + "$REAL_SSH" -MNf "${masteropts[@]}" "$host" \ + /dev/null 2>$logfile fi exec "$REAL_SSH" ${opts[@]} "$host" "$@" ;;