#!/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
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
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