Path for sh file called from Shell Command

Setup: Rpi3 running 0.117.4

Im trying to set up an automation which calls a script that again calls a shell command to launch the end point, a .sh file from the file system…

I get the following error when running the script:
download: Error executing script. Unexpected error for call_service at pos 1: [Errno 2] No such file or directory: ‘/scripts/download.sh’

Script Config:
service: shell_command.download
data_template:
movie: ‘{{ movie }}’

Shell Command:
movie: /scripts/download.sh “{{movie}}” 0 (this is the file location referred to in the log)

The download.sh file is located in the following folder on the SD Card:
/root/config/scripts/download.sh

I have tried a number of different paths (/script/, /local/script/, /) but none seem to work…

How do I find the correct path to call?

/config/scripts/download.sh

Your config directory is /config in the container where HA runs.

Nope… :frowning:

download_movie: Error executing script. Unexpected error for call_service at pos 1: [Errno 2] No such file or directory: ‘/config/scripts/download.sh’


➜ scripts pwd
/root/config/scripts
➜ scripts ls -la
total 20
drwxrwxrwx 3 root root 4096 Nov 6 19:38 .
drwxr-xr-x 9 root root 4096 Nov 6 19:40 …
-rwxrwxrwx 1 root root 114 Nov 6 10:11 download.sh

You may need to put it in the config directory itself, rather than in a subdirectory. You can confirm what the container can access by running ‘docker exec -it homeassistant /bin/bash’ from ssh and see for yourself.

hmm… not sure what I am looking for, but it still does not work… I’ve tried to place the .sh file in both /config and /config/scripts (and amended the shell command accordingly.

➜ ~ docker exec -it homeassistant /bin/bash
bash-5.0# pwd
/config
bash-5.0# ls -la download.sh
-rwxrwxrwx 1 root root 114 Nov 6 10:11 download.sh
bash-5.0#

Sometimes that error can be misleading, and instead refers to an inability to find the shell that you specify in the script (i.e., #!/bin/bash or whatever - the “shebang”) and not the script itself. For instance, if you had #!/foobar/foo as the first line in your script and that executable doesn’t exist, then you may get a “not found” error, even if it found your script and tried to execute it.

Here’s one of my shell commands for my adjustable bed:

In a script:

- service: shell_command.mbr_bed_mem2

in configuration.yaml:

shell_command:
  mbr_bed_mem2: /config/bed-codes/bed mem2

The bed shell script:

name=/config/bed-codes/$1.bin
result=$(cat $name | nc -n -u -w1 192.168.1.164 50007)

if [ "$result" = "ACK3" ];
then
        echo "Success"
else
        echo "Failed"
fi

Note in this case that I also have it in a subdirectory (bed-codes), so that should be okay.

Thanks for trying to help Rob… I’ve finally got it working (after wasting the entire morning)… in the end it was a combination of things… but I now run the command over ssh rather than straight off file system… and I had to add this to the top of the download.sh file:

#!/usr/bin/env sh

rather than #!/bin/bash which it had.