Shell Command: return code 127 - path to script?

So here is what I am attempting to do and I am sure there is a smart more efficient way to do this but I am new to home assistant. And there is always a million other ways to skin a cat so to speak.

I have six ring floodlight cameras. I wrote scripts in python to activate all the sirens and lights on all six cameras with the goal of using this as a part of an alarm automation. So if the alarm is triggered it will activate the indoor and outdoor sirens on all six exterior ring flood light cameras and turn on the flood lights.

Because of the latency of connecting to each ring device using the rest api, I wrote six python scripts to connect to each device and then activate the siren. I then wrote a shell script run all 6 scripts in parallel. I did this because running it in parallel in python caused connection errors exceeding retries…some sort of flood prevention I guess. Anyways, so this all works and is testing good. I execute the bash script and it in turn activates all 6 python scripts simultaneously for both the flood lights and sirens.

Eventually I will use that shell script in an automation via the service shell_command.turn_on_ring_siren

when executing the service from the Hassio UI I get the following error:

Error running command: bash /usr/share/hassio/homeassistant/scripts/ring_activate_all_siren.sh, return code: 127

Here is all the details:

configuration.yaml:

shell_command:
  turn_on_all_floodlights: bash /usr/share/hassio/homeassistant/scripts/turn_on_all_floodlights.sh
  turn_off_all_floodlights: bash /usr/share/hassio/homeassistant/scripts/turn_off_all_floodlights.sh
  turn_on_ring_siren: bash /usr/share/hassio/homeassistant/scripts/ring_activate_all_siren.sh

Here is the bash script ring_activate_all_siren.sh:

#!/bin/bash
python backyard_grill_siren_on.py &
python backyard_sheds_siren_on.py &
python backyard_siren_on.py &
python backyardtables_siren_on.py &
python front_yard_deck_siren_on.py &
python frontyard_siren_on.py

I set permissions for the entire scripts folder, but more specifically the files mentioned are:

-rwxrwxrwx 1 linuxbox users 217 May 25 16:40 ring_activate_all_siren.sh
-rwxrwxrwx 1 root users 4096 May 24 23:30 ._turn_on_all_floodlights.sh
-rwxrwxrwx 1 root users 246 May 24 23:41 turn_on_all_floodlights.sh

I tried a test someone else mentioned and got the same error:

Fri May 25 2018 18:34:06 GMT-0800 (AKDT)

Error running command: `/usr/bin/touch /tmp/hass-shell-command-test`, return code: 127
NoneType: None

scripts.yaml:

#test a simple shell script
  shelltest:
    sequence:
    - service: shell_command.test

configuration.yaml:

shell_command:
  turn_on_all_floodlights: bash /usr/share/hassio/homeassistant/scripts/turn_on_all_floodlights.sh
  turn_off_all_floodlights: bash /usr/share/hassio/homeassistant/scripts/turn_off_all_floodlights.sh
  turn_on_ring_siren: bash /usr/share/hassio/homeassistant/scripts/ring_activate_all_siren.sh
  test: /usr/bin/touch /tmp/hass-shell-command-test

for the siren script I have tired it with and without bash, with and without single quotes.

I am running hassio as a docker container on ubuntu 18.04 by the way.

Any ideas?

Hi! I am running in a similar issue and have, like you done as well, been trying different paths or /bin/bash in front of the command and with or without the use off ‘…’ around the commands.
No luck…

Have you found out the correct method of setting up the shell_command and solved your issue?

I’m also running hassio as docker container on ubuntu 18.04, and I also got “return code: 127” when I try to run a shell_command: shutdown.sh.

To identify the correct path to the script I did this

configuration.yaml
  shell_command:
    shutdown_esxi: touch meh
automation.yaml
- alias: test automation
  trigger:
  - platform: state
    entity_id: group.power_outage_monitoring
    to: 'off'
  condition: []
  action:
  - service: homeassistant.toggle
    entity_id: switch.test_switch
  - service: shell_command.shutdown_esxi

and manually trigger the automation. The test_switch has been trigger so I know the action has executed. I ssh into the ubuntu host (not the ssh add-on) so I search the whole harddrive for the file “meh” where it reside. so end up I found it under /usr/share/hassio/homeassistant/

so without path == /usr/share/hassio/homeassistant/
then if I put the script under /usr/share/hassio/homeassistant/script/esxi/shutdown.sh, I’ll need to call it with

shell_command:
  shutdown_esxi: ./script/esxi/shutdown.sh   <---- there is a dot in front of /script

hope it make sense.

Guys, I am struggling to use this to run Kodi in Raspbian or any other app. I made a script, put in folder

/usr/share/hassio/homeassistant/kodi.sh

the script is:

#!/bin/bash

kodi

When I run the script from Raspbain, it works. When I run the script from Hassio its code 127:

Sun Nov 24 2019 12:05:40 GMT+0100 (Středoevropský standardní čas)
Error running command: ./kodi.sh, return code: 127

I did not forget to use ./ (the dot)

There might be problem with permissions however I set:

chmod u=rwx,g=rwx,o=rwx kodi.sh

Any other idea what could work?

maybe because hassio runs inside docker, and hassio itself can’t run kodi?

I am not sure this is the case. The config files including the script are not in the docker. You can access them normaly from raspbian. There will be another issue. But i am quite noob in linux.

But you are using Hassio to CALL the script, which is running inside a docker container.

So basically what you are saying is giving me the hint that I need to send first SSH login command to log in to host machine and then send the command what I want.

Can I put all those commands inside the script? - I will try
What i need to put in SSH command? - Let me check :slight_smile: hopefully I will figure it out.

Yep

Should be able to put all those commands in your shell_command or script

You will need an SSH key to the host, point your shell_command or script to the key, and on the end of the ssh command just run your command instead of a script.

It works, I will put the guide i the thread nobody answered me so all know how to get it work

Voila Raspbian Hassio Run Kodi Automation