]> arthur.barton.de Git - trigger-rcmd.git/blobdiff - scripts/trigger-rcmd
Redirect stderr when calling shutdown, too
[trigger-rcmd.git] / scripts / trigger-rcmd
index a2bf18f04dd5d06ab85db1d39df861d5d2f746c5..55df7388492355dbcd38e194194298281d2de408 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 #
 # trigger-rcmp: Trigger remote commands
-# Copyright (c)2014-2016 Alexander Barton (alex@barton.de)
+# Copyright (c)2014-2017 Alexander Barton (alex@barton.de)
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -102,7 +102,7 @@ do_rcmd() {
                if [ "$rsys_users" = "0" ]; then
                        echo "$NAME: Power off \"$SYSTEM\" again ..."
                        # shellcheck disable=2029
-                       ssh -o PreferredAuthentications=publickey -q "$SYSTEM" "sync; shutdown -hP $SHUTDOWN_TIME" >/dev/null
+                       ssh -o PreferredAuthentications=publickey -q "$SYSTEM" "sync; shutdown -hP $SHUTDOWN_TIME" 2>&1 >/dev/null
                        if [ $? -ne 0 ]; then
                                echo "$NAME: Failed to power off \"$SYSTEM\"!" >&2
                                return 5
@@ -164,8 +164,14 @@ while [ $# -gt 0 ]; do
                fi
                NAME=$BASENAME
        fi
-       [ $r -ne 0 ] && result=1
+       if [ $r -ne 0 ]; then
+               # Exit code indicates an error. But only flag this as error
+               # when target should have been woken up and the indicated error
+               # is not "system down" (9).
+               [ -z "$NO_WAKE" ] || [ $r -ne 9 ] && result=1
+       fi
        shift
-       [ $# -gt 0 ] && echo
 done
+
+echo "$NAME: All done, exit code $result - $(date "+%Y-%m-%d %H:%M:%S")"
 exit $result