sramsay
(Stuart Ramsay)
October 4, 2017, 1:21pm
1
Hi all,
I am trying to set a switch in Hassio to execute a shell command when switched. Everything appears to be running fine in the logs etc but the action is not executed. Basically its a start command for on and a stop command for off to a linux device.
so in my switch config I have the following…
- platform: command_line
switches:
openvpn:
command_on: ssh [email protected] '/etc/init.d/openvpn start'
command_off: ssh [email protected] '/etc/init.d/openvpn stop'
Just to note that if I run these commands in PuTTY in windows, it works…
/etc/init.d/openvpn start
/etc/init.d/openvpn stop
I’m sure I must just be missing something silly…or I’m kidding myself that its possible
1 Like
haemish
(Haemish)
October 4, 2017, 1:47pm
2
Hi,
Does root not have a password on the server 192.168.0.65.
You may need to use sshpass -p your_password ssh user@hostname ‘then your command’
H
sramsay
(Stuart Ramsay)
October 4, 2017, 1:49pm
3
there is no password.
When I login via PuTTY I put in the internal IP address, hit connect and then the terminal asks for username (which is root)
sramsay
(Stuart Ramsay)
October 4, 2017, 1:51pm
4
I can also fire off these commands from an android device using an app called HandySSH with IP address and username (password blank) and they work?
haemish
(Haemish)
October 4, 2017, 2:09pm
5
This is a shot in the dark but are you not supposed to enclose the command in “”.
The examples suggest that you may need to:
platform: command_line
switches:
arest_pin_four:
command_on: “/usr/bin/curl -X GET http://192.168.1.10/digital/4/1 ”
sramsay
(Stuart Ramsay)
October 4, 2017, 2:15pm
6
I was under the impression that single and double quotes were generally equivalent using YAML, but it’s definatly worth a try.
I had tried amending where the quotes (single) were placed like the below but had no luck.
command_off: ssh [email protected] '/etc/init.d/openvpn stop'
command_off: 'ssh [email protected] /etc/init.d/openvpn stop'
command_off: ssh '[email protected] /etc/init.d/openvpn stop'
Have you tried:
command_off: "ssh [email protected] '/etc/init.d/openvpn stop'"
This works for me.
sramsay
(Stuart Ramsay)
October 4, 2017, 2:37pm
8
I havn’t, but I will now and let you know
Here are some tips about shell command problems.
I got this to work… I forgot HA runs in a virtualenv ,i had to run the ssh command line as HA user when venv was activated to accept the key. From there everything else worked, try that
@sramsay