I’m trying to run a small shell script but not having success.
The script runs fine when run from terminal but not when triggered by Home Assistant.
I’m trying to trace the run with the creation of a file located at /tmp/duck.log , but it is not being created.
I’ve tried a few variations. Referring to /bin/ash in configuration.yaml sometimes gives a different error code compared to using /bin/bash.
The service touch_temp_slash_test does not add an entry to home-assistant.log, but does not create a file at /tmp/test. Running the command /bin/touch /tmp/test from the terminal does create the file.
I don’t have access to a /config directory directly from console, but the file has been placed in the HA config directory as shared by the samba plugin: /mnt/data/supervisor/homeassistant/
configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
shell_command:
update_duckdns: /bin/bash /mnt/data/supervisor/homeassistant/duckdns.sh
update_duckdns_referring_by_slash_config: /bin/bash /config/duckdns.sh
touch_temp_slash_test: /bin/touch /tmp/test
I think I see where the problem is, check your script and remove all the absolute paths. I inspected the HA container for you and found the following
root@svr1:~# podman exec -it homeassistant bash
svr1:/config# which bash
/bin/bash
svr1:/config# which curl
/usr/bin/curl
svr1:/config# which echo
/bin/echo
svr1:/config# /usr/bin/echo world
bash: /usr/bin/echo: No such file or directory
svr1:/config# which touch
/bin/touch
svr1:/config# ls /usr/bin/touch
ls: /usr/bin/touch: No such file or directory
The SSH and terminal addon is just another container and not the actual HA installation, which where the HA will run scripts from.
This means you might have commands available in the addon, which are not installed in the HA container, Or maybe they are just in another path.
It looks like console login is a really different environment to what HA is seeing, console doesn’t even have a which binary.
The update to duckdns.org goes through now. I haven’t traced where /tmp is from console’s perspective yet but I was able to write a log by changing the output directory to /share . I’m guessing if I install & connect via the ssh addon things will be closer to the way HA sees things.
No, it will be the same as the terminal addon.
You need to make the special SSH access available, which is typical on port 22222 or something like that.
Or use the docker trick to run from the docker container, which should be possible both from the terminal and SSH.