From: Mark Wooding Date: Fri, 10 Apr 2015 14:19:25 +0000 (+0100) Subject: rsync-backup.in (run): Option to preserve standard input. X-Git-Tag: 1.1.0~4^2~1 X-Git-Url: https://git.distorted.org.uk/~mdw/rsync-backup/commitdiff_plain/d482de4ccee16ff91e5128bc8829882d8a17b3f6 rsync-backup.in (run): Option to preserve standard input. Usually we close stdin and redirect from /dev/null so that SSH doesn't hang forever; but sometimes it's actually important. --- diff --git a/rsync-backup.in b/rsync-backup.in index a9145d6..e9bb3be 100644 --- a/rsync-backup.in +++ b/rsync-backup.in @@ -83,6 +83,14 @@ copy () { } run () { + stdinp=nil + while :; do + case $1 in + -stdin) stdinp=t; shift ;; + --) shift; break ;; + *) break ;; + esac + done tag=$1 cmd=$2; shift 2 ## Run CMD, logging its output in a pleasing manner. @@ -95,12 +103,13 @@ run () { nil) log "BEGIN $tag" rc=$( + case $stdinp in nil) exec &- 4>&- 5>&- 9>&- echo $? >&5; ) | copy "|" >&4; } 2>&1 | copy "*" >&4; } 4>&1 | - cat >&9; } 5>&1 &9; } 5>&1 ) case $rc in 0) log "END $tag" ;;