SUMMARY: My script which includes ssh runs fine from the command line but the ssh part does not work when the script is called by an an automated daemon (apcupsd).
DETAIL: I've got an ESXi server and I've got a CentOS 6.5 VM on it dedicated to monitoring an APC Backup UPS (via USB). I'm using APCUPSD to do this. The theory is that in the event of an extended powerloss it will ssh into the ESXi host to shut the system down. Everything works in terms of connectivity to the UPS and detecting power failure etc and calling a script (on the CentOS VM) when the time comes to do the shutdown.
I have setup keys using ssh-keygen etc so I can ssh into the ESXi host without needing a password.
If I run the script manually from the command line it works fine.
But it doesn't when called automatically by apcupsd.
Specifically it is the ssh command that isn't working (other lines in my script run fine).
I've tried changing the command I'm running to a simple ls and redirecting output to a file (again this works fine when run manually from the command line).
When triggered automatically my output file is created but it is zero bytes.
I've tried numerous different options with SSH including -i and -n. I can't seem to get any detailed error messages (e.g. with -v)
Looking at /var/log/auth.log on the ESXi host it suggests it hasn't even attempted to make a connection.
A few things I've tried:
/usr/bin/ssh -o StrictHostKeyChecking=no -x root@X.X.X.X "ls" >output_file
/usr/bin/ssh -n -i /root/.ssh/id)dsa root@X.X.X.X "ls" >output_file
ssh -n root@X.X.X.X >output_file
If I echo $? >output_file
I get a return code of 126 which I believe is CLI_ERR_NOT_AUTHORIZED Authorization error: the user does not have sufficient privileges to execute command. The thing is I believe apcupsd will be running as root so I would have thought it would have the necessary privileges.
Can anybody help?