Cannot execute shell_command, command not found for custom executable

Hey everyone, I have tried a number of combinations, but everything useful returns 127 command not found. I am doing something silly, right?

shell_command:
  kodi_cecactivate_for_tv: "./kodi_send_udp_action" # nope
  kodi_cecactivate_for_tv_1: "kodi_send_udp_action" # na
  kodi_cecactivate_for_tv_2: "bash -c 'kodi_send_udp_action'" # no sir
  kodi_cecactivate_for_tv_3: "touch here_kodi_send_udp_action" # yeah... but not helpful
  kodi_cecactivate_for_tv_4: "pwd; ./kodi_send_udp_action" # nothing
  kodi_cecactivate_for_tv_5: "bash -c 'pwd; ./kodi_send_udp_action'" # no dice
$ ls -la ~/config/*kodi*
-rw-r--r--    1 root     root             0 Apr 19 19:16 /root/config/here_kodi_send_udp_action
-rwxr-xr-x    1 root     root       5374764 Apr 19 19:01 /root/config/kodi_send_udp_action

FYI this sends a UDP packet to Kodi for the CECActivateSource() command that is not exposed on the Jsonrpc API.

The logs. The thing that confuses me is all errors returning 127.


Error running command: `./kodi_send_udp_action`, return code: 127
Error running command: `kodi_send_udp_action`, return code: 127
Error running command: `bash -c 'kodi_send_udp_action'`, return code: 127
Error running command: `pwd; ./kodi_send_udp_action`, return code: 127
Error running command: `bash -c 'pwd; ./kodi_send_udp_action'`, return code: 127
Error running command: `/root/config/kodi_send_udp_action`, return code: 127
Error running command: `./config/kodi_send_udp_action`, return code: 127

I should try a different executable next.

Try /config/kodi_send_udp_action, what does that give you?

FYI this:

isn’t actually where Home Assistant sees the file. The SSH add-on runs in a totally different container from HA itself. In the SSH container the directory where HA config is stored is mounted at /config and there is a symlink created to map /root/config/config. The HA container does not have this symlink, /config is where the config folder lives. The HA container also has different packages installed then the SSH container so there’s a whole host of reasons why a script that seems to work in the SSH container can fail when run as a shell_command

For more info on these different containers and how to test your commands/scripts as HA sees them rather then as the totally separate SSH container happens to see them see here:

The topic is a bit different but the section on trying commands from the HA container is relevant.

Good spotting, i had the wrong path. I agree the docker containers confuse people.

I simplified my examples and seems the HA command takes issue with this particular binary…

config $ ./kodi_send_udp_action
UDP target IP: 192.168.1.44
UDP target port: 9777
message: CECActivateSource()
config $ echo $?
0
config $ ./testscript.sh
yes, I am a script
config $ echo $?
99

In HA

  kodi_cecactivate_for_tv: "./kodi_send_udp_action" # nope
  testscript_2: "./testscript.sh"
2022-04-20 09:48:27 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `./kodi_send_udp_action`, return code: 127
NoneType: None
2022-04-20 09:48:40 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `./testscript.sh`, return code: 99
NoneType: None

(I used exit 99 so it shows in the logs)

Before going to much further, I notice what you’re trying to do seems to be called CECActivateSource. Have you seen the HDMI-CEC integration? Not sure if that will work for you but figured it couldn’t hurt to ask. Generally easier to use an OOTB solution when possible.

Back to your examples, where does the binary live? kodi_send_udp_action is a script right or is that the binary? If it’s a script calling a binary then you have to make sure that HA can see both the script and the binary. Which generally means they both have to live in /config.

EDIT: Also if you set the log level of homeassistant.components.shell_command to debug then it should print stdout and stderr to the log. That usually helps me track down confusing issues in this space.

Kodi is another raspberry pi with HDMI whereas HASS hasn’t got the Reciever/TV connected. If this changes the HDMI-CEC integration is the way to go.

Both the bash script and the binary are in /config and I am now fairly certain the binary is throwing the 127.

For the life of me I cannot find where to disable protection mode for the ssh add-on… I am sure I have seen that option somewhere. I need access to the hass container.

You need to install the one from the community add-ons store. Then you can turn off protection mode on the first tab next to watchdog, start on boot, etc.

1 Like

Ahh the not Terminal & SSH but the HACS enhanced SSH & Web Terminal. Thanks

Here is my issue with the pyinstaller binary

bash-5.1# ./kodi_send_udp_action
Error loading shared library libz.so.1: Operation not permitted (needed by /config/kodi_send_udp_action)
Error relocating /config/kodi_send_udp_action: zlibVersion: symbol not found
Error relocating /config/kodi_send_udp_action: inflate: symbol not found
Error relocating /config/kodi_send_udp_action: inflateInit_: symbol not found
Error relocating /config/kodi_send_udp_action: inflateEnd: symbol not found
bash-5.1# echo $?
127

Sadly it was a bit of waste of time and I have gone full circle. The only reason i did this (pyinstaller binary) was because when I sshed in there was no python available.

Now that i test this in the correct container which does have python i can revert back to using a python script. Script is here HDMI CEC to turn on TV and AVR no longer working - #4 by kcd

I next I will post the working config. Which does indeed work! Thanks for your help