3 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
7 Usage: relay-cmd poweroff|poweron|reboot HOSTNAME|CHANNEL [RELAY_ID]
9 RELAY_ID is not needed if only 1 relay device is connected. To
10 understand CHANNEL and RELAY_ID, run hidusb-relay-cmd and
11 hidusb-relay-cmd state. I recommend writing a config in
12 /etc/relay-cmd.conf , then using HOSTNAME instead of CHANNEL and
13 RELAY_ID. It serves as documentation of what you connected the relay
16 # This config is just sourced from bash, so make sure its valid bash.
17 # relay_id is not needed if only 1 relay is connected.
19 cephserver3_relay_id=HURTM
21 cephserver2_relay_id=HURTM
31 read action chan relay_id
<<<"$@"
33 if [[ -e /etc
/relay-cmd.conf
]]; then
34 source /etc
/relay-cmd.conf
37 # we know HOSTNAME is given if it doesn't start with a number.
38 if [[ $chan != [0-9]* ]]; then
39 chan_var
=${chan}_channel
41 if [[ ! $chan ]]; then
42 echo "error: channel not found in /etc/relay-cmd.conf" >&2
45 if [[ ! $relay_id ]]; then
46 relay_id_var
=${chan}_relay_id
47 relay
=${!relay_id_var}
52 if hidusb-relay-cmd state |
grep ON
; then
53 printf "%s\n" "WARNING: output from hidusb-relay-cmd state shows an ON relay. this could mean another command instance is running, or it got stuck on due to an uncompleted command." >&2
57 case $
(hidusb-relay-cmd state|
wc -l) in
59 echo "error: got 0 lines from running hidusb-relay-cmd state" >&2
64 if [[ ! $relay_id ]]; then
65 echo "error: more than 1 relay device, so passing its id is required" >&2
72 if [[ $relay_id ]]; then
73 # leave this as an empty var if its not passed
74 relay_id_arg
="id=$relay_id"
84 # ignore hup so we complete even if there is a connection problem.
86 echo "$0: doing $action. shell commands are printed to the terminal:"
89 v hidusb-relay-cmd
$relay_id_arg on
$chan
91 v hidusb-relay-cmd
$relay_id_arg off
$chan
94 v hidusb-relay-cmd
$relay_id_arg on
$chan
96 v hidusb-relay-cmd
$relay_id_arg off
$chan
99 v hidusb-relay-cmd
$relay_id_arg on
$chan
101 v hidusb-relay-cmd
$relay_id_arg off
$chan
103 v hidusb-relay-cmd
$relay_id_arg on
$chan
105 v hidusb-relay-cmd
$relay_id_arg off
$chan
108 echo "error: action arg not supported" >&2
111 echo "$0: script ended. exiting"