izakstern
(Izak Stern)
January 15, 2020, 1:29pm
1
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!
H102
(CM6.5 H102)
January 15, 2020, 1:57pm
2
Does user openhab have permission to the correct file and proper groups?
izakstern
(Izak Stern)
January 15, 2020, 2:00pm
3
I think so, because executing remote-commands itself are no problem. It begins if i use parameters…
H102
(CM6.5 H102)
January 15, 2020, 2:05pm
4
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
izakstern
(Izak Stern)
January 15, 2020, 2:17pm
6
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…
H102
(CM6.5 H102)
January 15, 2020, 2:24pm
7
Try a ./ before the user host name.
alexxio
(Alessio)
January 15, 2020, 2:29pm
8
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
H102
(CM6.5 H102)
January 15, 2020, 2:35pm
9
That was going to be my next suggestion as the doc’s mention to use the scripts directory for such.
1 Like
izakstern
(Izak Stern)
January 15, 2020, 2:52pm
10
Using a Shell-Script does the trick. I don’t understand it, but target is reached
Thank you very much!
rossko57
(Rossko57)
January 15, 2020, 2:57pm
11
Relevant info -
I can elaborate just a little bit.
When you log into a command line on a Linux/Unix/BSD type machine you are using what is called a “shell”. That is what sh, bash, ksh, zsh, fish (my favorite) etc. are all about. They provide your user interface between the terminal and the operating system. I want to say that again, it is a user interface.
A lot of the stuff that you find when using the command line is implemented by the shell. This includes anything that has to do with text redirection and …
izakstern
(Izak Stern)
January 15, 2020, 3:00pm
12
Thank you for the information, maybe useful in another commands!
1 Like