Hass/hassio shell command not working

I have no idea if this problem is hassio or hass related so i try to get help here. I use hassio on raspberry pi zero.

I have tried different shell commands to call a batch file

shell_command:
  server_oben_runterfahren: /bin/bash /data/shutdown_server.sh
  server_oben_runterfahren_2: '/bin/bash /data/shutdown_server.sh'
  server_oben_runterfahren_3: 'data/shutdown_server.sh'

Here is the batch file content
#!/bin/bash
#ssh -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] “sudo shutdown -h now”
date > log.txt

I also tried the command direct in hass config, without luck.

When calling the first shell command direct over ssh on hassio machine it is working as wanted. I have no more idea how to fix that.

I though maybe a user problem but there is no user hass or hassio to give access to the batch file.

Has anyone an idea how to get the shell command working? I need to call the batch file or direct the ssh command.

Anyone with an idea maybe? Please :relaxed:

Does anyone know of shell commands are supported when running a hassio setup ?

@rqleslie

I just tried myself and shell_commands work in hassio 0.53.

in configuration.yaml

shell_command:
  set_musiccast_link: 'bash /config/bin/set_musiccast_server.sh {{server}} {{client1}} {{client2}}'

the bash script is running some curl commands

interesting thanks very much - I will give this a try

Did you create that bin folder under config ?

I can do whatever i want i can not bring Hassio to run my command. I tried lot of things like setting chown to root or root:root set commands in script files or direct into hassio

shell_command:
server_oben_runterfahren: ‘bash /config/bin/shutdown_server.sh’
server_oben_runterfahren_sudo: ‘sudo bash /config/bin/shutdown_server.sh’
server_oben_runterfahren_direkt: ‘ssh -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] “sudo shutdown -h now” > someFile.txt’
write_date: ‘date > /config/bin/data.txt’

The only thing that works is the data > /config/bin/data.txt command in hassio, but running that from my script does not work. The ssh command is working over terminal in hassio but not in hassio itself.

I tried different version of this script

#!bash

#ssh -i /data/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] "sudo shutdown -h now" > someFile.txt

date > log.txt

No luck until know, anybody with an idea or solution how to fix that?

Copy your .ssh folder to “/config/.ssh/” instead and execute the shell_command like this:
turn_off_TARGET: ‘ssh -i “/config/.ssh/id_rsa” hass@TARGET “shutdown.exe -h now”’

This of course implies that you’ve properly configured the TARGET for autologin and trusted it, but it’s working for me.

Thanks to @ixniz, now it is working. I needed to change the shutdown command because i have linux but it works now, finally!!! :grinning:

1 Like

I have the same problem…

scala_inf_status: mosquitto_pub -d -h 192.168.8.200 -u xxxxx -P xxxxx -t ‘cmnd/scala_inf/status’ -m ‘0’

But the log file return me this error:

Error running command: mosquitto_pub -d -h 192.168.8.200 -u xxxxx -P xxxxx -t 'cmnd/scala_inf/status' -m '0', return code: 127
Error running command: `mosquitto_pub -d -h 192.168.8.200 -u p
NoneType: None

I troubleshoot my shell_commands as follows:
First i login with ssh to my home assistant device and try to run that shell command from there.
If it doesn’t work, i have found the issue and will troubleshoot there.
If it works on ssh it is most likely a permissions problem, so checking with ls -al if my hass-user has permissions to execute my command (i mostly use .sh files to run my commands). If that is all set right all that is left is a spelling problem in my config.yaml