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