[SOLVED] Exec-Binding with SSH and Parameters

Hello!

I have a problem using SSH via Exec-Binding if the commands have parameters…

Using this Thing:

Thing exec:command:unixshutdown_octopi [command="/usr/bin/sshpass -p<pw> /usr/bin/ssh -o StrictHostKeyChecking=no <user>@<host> 'sudo shutdown -h now'", interval=0]

I know that i should user other techniques than a cleartext-password here, i will do that later.

The result of this is “command not found”. If i use commands without parameters it works.
Example:
If i change ‘sudo shutdown -h now’ to ‘hostname’, it shows me the hostname of the remote host.
If i change ‘hostname’ to ‘hostname -i’, it shows me ‘command not found’.

I tried to set @@ for every space, but no function. Any Idea?

Thank you!

Does user openhab have permission to the correct file and proper groups?

I think so, because executing remote-commands itself are no problem. It begins if i use parameters…

What’s the output from the logs and what happens if you remove sudo ?

Does the user OpenHAB have a known_hosts file in the .ssh directory of its home directory?

1 Like

It doesnt matter. I tried another commands like “hostname” or “uid” (without sudo). They are working until i use parameters like “hostname -i”

same if use something like “hostname | grep abc”

I think i could be something around escaping characters…

Try a ./ before the user host name.

Have you tried to create a .sh script with those commands inside?
Put it into the scripts directory and give openhab user ownership.
This way you can call it inside the exec command with just the absolute path and there should be no characters problem.

3 Likes

That was going to be my next suggestion as the doc’s mention to use the scripts directory for such.

1 Like

Using a Shell-Script does the trick. I don’t understand it, but target is reached :wink:

Thank you very much!

Relevant info -

Thank you for the information, maybe useful in another commands!

1 Like