Executing a shell command to linux

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
      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 :slight_smile:

1 Like


Does root not have a password on the server

You may need to use sshpass -p your_password ssh user@hostname ‘then your command’


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)

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?

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
command_on: “/usr/bin/curl -X GET

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.

I havn’t, but I will now and let you know :slight_smile:

it didn’t work :frowning:

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