Exec not execing

I have a switch item, with the exec binding. The command is:
OFF:ssh pi@ sudo /etc/init.d/webcam.sh restart
I have it in a sitemap, with the mapping
So it shows up all nice.

When I tap the Restart button in my sitemap, I see in my log
executed commandLine 'ssh pi@ sudo /etc/init.d/webcam.sh restart'
but nothing happens.

If I manually run the complete command
ssh pi@ sudo /etc/init.d/webcam.sh restart
from the machine that is running openhab, I can see that it executes, and everything works fine.
I’ve also tried a different command, like /sbin/shutdown -r now, and it’s the same thing.

SSH is configured fine.

What is the problem here? Or how should I debug to see the output of the exec, what does the second machine respond when it receives the command?

I had the same problem. I solved it by turning my switch into a dumb switch and creating a rule that calls the command using executeCommandLine(cmd, timeout) and logged out the result.

For me the problem was tge private key in openhab’s .ssh folder had - rw-r–r-- permissions but needed to be - rw------. It worked fine when executed from the command line and only threw the error when run using the exec binding.

It could also be that openHAB runtime is running under a different user than the one where @alex_bartis types the command manually.

@watou that was the problem! Thank you, and thank you @rlkoshak!

My OH was running as root. I needed to add root’s key to the other machines authorized_keys.