I am trying to add a command into a script to shut down my NAS when the
UPS detects a power loss. There is a daemon apcupsd which gets a signal
from the UPS and runs various scripts which can be modified by the user.
I have a script doshutdown as follows
#!/bin/sh
... various messages and sleep delays
/usr/bin/ssh root@nasbox poweroff
... more messages and sleep delays
The ssh command in my script does not run in a power off test
(everything else in the script works i.e. the messages and delays), but
if I run the ssh command interactively from the usual graphical terminal
(as root) it shuts down the NAS, so the NAS isn't stopping it working
assuming its getting the appropriate handshaking from ssh.
My knowledge of how to get daemon scripts working and how to use ssh is
almost nil. Also I can't find a way to get any error output which the
ssh command might be issuing. I've tried enclosing the body of the
script in brackets to redirect output to files:
{
} > /data/temp/shutdown-out.txt 2> /data/temp/shutdown-err.txt
I've looked in syslog, kern.log and auth.log without finding anything.
So I'm scrambling around in the dark. Currently my vague ideas as to
what might be wrong are:
script doesn't know what nasbox is (it is defined in /etc/hosts)
ssh is being run without being associated as root
ssh cannot find root's keys
nas doesn't recognise login as authorised user
I'm also starting to think I am stressing the UPS too much by running
too many power off tests, so I'd like to resolve this without too much
more experimentation.
Grateful for any suggestions. I'm running Linux Mint 17.3 (based on
Ubuntu 14.04, based on Jessie). Uses openssh (1:6.6p1-2ubuntu2.8)