Exec commands are not working

I tried to use exec bindings to shutdown by NAS Synology but the command is not executed. If I display the openhab logs (tail -f /var/log/openhab/openhab.log) I can see this message : .2016-04-01 00:35:50.842 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine ‘ssh root@ sudo shutdown -h now’

Below I will write what I already done:

  • I copied the exec binding file in addon directory
  • manually, from my RP2 (where is Openhab 1.8 installed) the command is executing without enter any password (I’m using SSH keys) .
  • I done :
  • and also adduser openhab sudo

The item file that I’m using is:

Switch synology “Synology” (gDevices) {nh=“”, exec=">[OFF:ssh root@ sudo shutdown -h now]"}

Also I tried “local” to restart the RP2 and It sames that is working
I used:
Switch synology “Synology” (gDevices) {nh=“”, exec=">[OFF: sudo shutdown -h now]"}

Please let me know what I done wrong…

MY advice when debugging the exec binding is to don’t use the exec binding and instead use the executeCommandLine in a rule and log what the command returns. It is the only way to discover what errors are being generated.

In my experience getting ssh to work from openHAB is challenging and the more common problems I’ve seen:

  • the user OH is running under has not accepted the ssh key for the remote host yet
  • the user OH is running under is not configured with the right keys to ssh to the remote host without a password
  • the permissions on the files in .ssh are too open and the remote host refused the connection

In all of these cases you can only see these errors by running it from a rule and logging the resuts.

val String results = executeCommandLine("ssh root@ sudo shutdown -h now", 5000)
logInfo("Exec test", results)

Once you are sure ssh is working, if you are logging in as root to your NAS, then you don’t need to use sudo to run the command.

Thank you for your prompt and complex answer.

Thank you for all your answers. Hopefully I found the problem… I didn’t know that exec is also a persistence not only a binding. Maybe that’s why | didn’t see that I have only exec persistence file copied. After I add the exec binding everything works fine :wink:

Not sure on the exec part but the command should be:
executeCommandLine(“sudo ssh root@ shutdown -h now”

This IS assuming you already setup password-less ssh.