Shell_command - not working (HA on a docker) error -11

Thanks @finity - will check this ,
It can be kind of risky implement some of the things there in qnap env ,

Thanks @HomAut ,
I have a ssh server running (build in feature in QNAP),
the question is if the HA docker “see” it?
case not , how can i enable it?

I managed to run those command using command_line switch ,
Wonder why command_line allow executing “extrenal” commands and not shall_command?

platform: command_line
switches:
masking_camera:
command_on: 'curl --digest -u xxx:yyyy -g "http://192.168.1.111/cgi-bin/configManager.cgi..."'
command_off: 'curl --digest -u xxx:yyyy -g "http://192.168.1.111/cgi-bin/configManager.cgi..."'
value_template: '{{ value == "1" }}'
friendly_name: Cam Masking

btw - the command_line is great alternative and can be very useful ,
But i wonder if it can support more than ON/OFF/STATE ?
like a “multi-positions” switch where each position can relate to different command_line scenario .
I believe it require command_line also support this ,
hopefully some1 from HA dev read this and like the idea:)

I guess I should have clarified that I’m running non-hassio HA in Docker.

Sorry, I’m not an expert. I just like to share my finding…
To run shell command you should write the script
Then you can fire the script via a call on your configuration.yaml or included files.

So you might write:

shell_command:
  restart_pow: touch ~/.pow/restart.txt      ## or your own shell script

then on configuration just set a trigger that will call the service restart_pow. But if you try to set through the UI, you’ll find you script listed (script.restart_pow). If not you probably need to restart HA.

@HomAut ,thanks for sharing,

If i understand it correctly,
I already tried that -
adding shell_command command which fire script (locate known HA folder config/tmp,
set_mask_true: /config/mask.sh

where mask.sh contain simple touch command .
restart -> execute from UI .
It didn’t work for me (error code -11).

Is that what u mean?

shell commands should work just fine without any SSH business, unless you need access to a binary that is not available in the container, or if you need access to the host.

Have tried to run the command from ssh login ?
Note that you should make executable at least for the HA user

sudo chmod 744 /config/mask.sh

### testing
./config/mask.sh

It won’t be bad if you give the whole path for your cli executable.
See here.

@HomAut

The HA installed on QNAP docker ,
I’m connecting to QNAP using SSH and run command ,
I guess u mean to connect with HA user ?
case yes, how can i get what HA user is using for ssh session (as same using for shell_command)?
And for the Q - Can some please explain why command_line allow executing “external” commands and not shall_command?

Sorry I’m misleading. I dismiss the use of docker.
I was supposing you could handle to modify permissions to the files, which is not simple for dockers.
But the /config/ is in an open file system. So once you login via SSH, you should switch to root command line, by login command. Then you might change permission in /config. Any how better list how are the other file permission.

ls -l config/

Actually i set permission the whole MAIN HA folder :

drwxrwxrwx 20 admin administrators 4.0K 2019-08-02 17:06 HA_new/

Even executing ~/.profile didn’t work


2019-08-02 14:23:19 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `. $HOME/.bashrc`, return code: -11
NoneType: None
2019-08-02 14:23:26 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `. ~/.profile`, return code: -11

There is no HA user.

sure it is. it’s extremely simple.

This literally only applies to Hassio.

/config is mapped to the host. You can modify permissions on the host to match the UID/GID inside the docker container, but the entire docker instance runs as root, so you don’t have to worry about that.

Sound like u have solution? Would really appreciate ur help

It seems like there is a LOT of confusion in this thread alone. There have been some assumptions that you are using hassio, and I think there needs to be some clarification.

In the OP, you are attempting to run those commands directly inside the docker container running HA.

Can you clarify EXACTLY what you want to do?

Thanks ,

I might be confused myself :blush:
I mention in first post:
running HA 0.95.4 on a docker(Qnap),
not a hassio version .

I’m having issue executing shell_command ,

What i want to do:
To be able to execute curl command to set IP camera into positions
or setting up some configurations.

I started with basic commands and all return error code -11 .
for making things clear:

I create shell_command.yaml contain some test command :

test_1: . $HOME/.bashrc
test_2: . ~/.profile

test_3: ./config/MyScripts/mask.sh
test_4: ./share/Avi/HA_new/MyScripts/mask.sh

in config/MyScripts
I place simple mask.sh

#!/bin/sh
touch ${PWD}/test.txt
exit 0

I’m testing the commands from the UI,
from developer tab --> services
shell_command.test_1
shell_command.test_2

error code -11
return for all commands i tried .

Doesn’t exist inside the docker container

These don’t exist either.

The correct filepath is /config/MyScripts/mask.sh

shell_commads:

test_1: "/config/MyScripts/mask.sh"
test_2: "/bin/bash /config/MyScripts/mask.sh"
test_3: "bash /config/MyScripts/mask.sh"
test_4: "bash /share/Avi/HA_new/MyScripts/mask.sh"

Return:

2019-08-02 16:07:52 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/config/MyScripts/mask.sh`, return code: -11
NoneType: None
2019-08-02 16:08:04 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash /config/MyScripts/mask.sh`, return code: -11
NoneType: None
2019-08-02 16:08:11 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash /config/MyScripts/mask.sh`, return code: -11
NoneType: None
2019-08-02 16:08:23 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash /share/Avi/HA_new/MyScripts/mask.sh`, return code: -11

Did you make the script executable?

chmod +x /path/to/config/file

Yes ,
Actually I set all HA :


drwxrwxrwx 20 admin administrators 4.0K 2019-08-02 17:06 HA_new/

Well the directories are executable by default, otherwise we cannot access them.

Chmod the file itself

Are you running the stream component?

Might want to try turning it off and removing camera_view: live: https://github.com/home-assistant/home-assistant/issues/22999.