chiark / gitweb /
check, rcheck: Propagate exit status better; capture lines more precisely.
[rcheck] / rcheck
diff --git a/rcheck b/rcheck
index cd40440567e622218afcfab597d44031404a021d..318aab6066907761875352acf4dd4ed45262dc43 100755 (executable)
--- a/rcheck
+++ b/rcheck
@@ -12,11 +12,15 @@ do
   prog=$(readlink "${prog##*/}")
 done
 
+exec 4>&1
+rc=0
 for host in "$@"; do
 
-  { { { set +e
-       tar czf - check check.d |
-       ssh "$host" '
+  nrc=$(
+    exec 5>&1
+    { { { set +e
+         tar czf - check check.d |
+         ssh "$host" '
 set -e
 cd /tmp
 
@@ -34,21 +38,25 @@ cd $tmpdir
 
 tar xzf -
 ./check'
-       rc=$?; set -e
-       case $rc in
-         0) ;;
-         *) echo >&2 "remote check process failed (rc = $rc)" ;;
-       esac
-      } 1>&3; } 2>&1 |
-    sed 's/^/!!! /'
-  } 3>&1 |
-  if read line; then
-    cat <<EOF
+         rc=$?; set -e; echo $rc >&5
+         case $rc in
+           0) ;;
+           *) echo >&2 "remote check process failed (rc = $rc)" ;;
+         esac
+       } 1>&3; } 2>&1 |
+      sed 's/^/!!! /'
+    } 3>&1 |
+    if IFS= read -r line; then
+      cat <<EOF
 ###--------------------------------------------------------------------------
 ### $host
 
 $line
 EOF
-    cat
-  fi
+      cat
+    fi >&4
+  )
+  if [ $nrc -gt $rc ]; then rc=$nrc; fi
 done
+
+exit $rc