From 8ef4954fc0372206f7d6ee8a3efbe07cb7de708f Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 27 Jan 2018 16:20:05 +0100 Subject: [PATCH 1/3] Redirect stderr when calling shutdown, too This is required to not trigger "error detection" of some mail wrapper scripts etc., that would notice output og shutdown(8) on stderr -- which outputs messages there, even when there is NO error ... --- scripts/trigger-rcmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/trigger-rcmd b/scripts/trigger-rcmd index 5d96d7f..55df738 100755 --- a/scripts/trigger-rcmd +++ b/scripts/trigger-rcmd @@ -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 -- 2.39.2 From 6bd8ced76b2db732ce380f6ce471e5c9cc1bf2a0 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sun, 20 Dec 2020 23:55:57 +0100 Subject: [PATCH 2/3] Enhance coding style, fix shellcheck(1) warnings --- scripts/trigger-rcmd | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/trigger-rcmd b/scripts/trigger-rcmd index 55df738..9ef9ad8 100755 --- a/scripts/trigger-rcmd +++ b/scripts/trigger-rcmd @@ -1,7 +1,7 @@ #!/bin/sh # # trigger-rcmp: Trigger remote commands -# Copyright (c)2014-2017 Alexander Barton (alex@barton.de) +# Copyright (c)2014-2020 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 @@ -41,27 +41,23 @@ do_rcmd() { fi echo "$NAME: Checking system \"$SYSTEM\" ..." - fping -c1 -q "$SYSTEM" 2>/dev/null - if [ $? -ne 0 ]; then + if ! fping -c1 -q "$SYSTEM" 2>/dev/null; then if [ -n "$NO_WAKE" ]; then echo "$NAME: \"$SYSTEM\" seems to be down, skipping job." return 9 fi echo "$NAME: \"$SYSTEM\" seems to be down, wake it up ..." - etherwake -b -i "$IFACE" "$(echo "$SYSTEM" | cut -d'.' -f1)" - if [ $? -ne 0 ]; then + if ! etherwake -b -i "$IFACE" "$(echo "$SYSTEM" | cut -d'.' -f1)"; then echo "$NAME: Failed to wake \"$SYSTEM\"!" >&2 return 3 fi echo "$NAME: Waiting for \"$SYSTEM\" to respond ..." for i in $(seq 1 $TIMEOUT); do - fping -c1 -q "$SYSTEM" 2>/dev/null - [ $? -ne 0 ] || break + fping -c1 -q "$SYSTEM" 2>/dev/null && break sleep 1s done - fping -c1 -q "$SYSTEM" 2>/dev/null - if [ $? -ne 0 ]; then + if ! fping -c1 -q "$SYSTEM" 2>/dev/null; then echo "$NAME: Failed to wake \"$SYSTEM\"!" >&2 return 4 fi @@ -102,8 +98,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" 2>&1 >/dev/null - if [ $? -ne 0 ]; then + if ! ssh -o PreferredAuthentications=publickey -q "$SYSTEM" "sync; shutdown -hP $SHUTDOWN_TIME" >/dev/null 2>&1; then echo "$NAME: Failed to power off \"$SYSTEM\"!" >&2 return 5 fi -- 2.39.2 From 1c8642ec5bbf52a9d1387ae4ce5685ed7803b120 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Tue, 22 Dec 2020 12:15:04 +0100 Subject: [PATCH 3/3] Fix another (last?) shellcheck(1) warning ... --- scripts/trigger-rcmd | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/trigger-rcmd b/scripts/trigger-rcmd index 9ef9ad8..102fe16 100755 --- a/scripts/trigger-rcmd +++ b/scripts/trigger-rcmd @@ -33,9 +33,7 @@ do_rcmd() { # Read in job/configuration file, but ignore shellcheck(1) warnings: # shellcheck disable=1090 - . "$cnf" - - if [ $? -ne 0 ]; then + if ! . "$cnf"; then echo "$NAME: Failed to read \"$cnf\"!" return 2 fi -- 2.39.2