I’ve got a shell script which perfectly executes in the terminal, but it wouldn’t work when executed as shell_command:
shell_command:
picture_snapshot_refresh: "/config/custom_components/imagegrab/imagegrab.bash"
The shell script downloads through a web API and uploads it to an FTP server. It looks similar to this:
# Downloads snapshot
# Uploads the file to public FTP folder
useragent="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11"
# Open connection
curl -c cookies.txt -A "$useragent" "http://www.myapiurl.com/api.cgi?foo=bar"
# Access Snapshot through API and save in file
curl -b cookies.txt -A "$useragent" -o snap.jpg "http://www.myapiurl.com/api.cgi?foo=bar"
# Close connection
curl -b cookies.txt -A "$useragent" "http://www.myapiurl.com/api.cgi?foo=bar"
# Upload file to FTP
curl -T snap.jpg --user myuser:mypassword ftp.foobar.com
I am running Home Assistant OS on an ODROID:
Home Assistant 2022.7.7
Supervisor 2022.07.0
Operating System 8.4
Frontend 20220707.1 - latest
Unfortunately, I also can’t find anything helpful in the logs (though I’ve set the log level to “debug”).
Where are these shell_commands executed?
Especially: in which directory, and with which privileges, are they sufficient to write files and execute curl -T commands to post a file to FTP?
The documentation states:
The command is executed within the configuration directory.
If you are using Home Assistant Operating System, the commands are executed in the homeassistant container context. So if you test or debug your script, it might make sense to do this in the context of this container to get the same runtime environment.
What does this exactly mean - how could I debug or test my script in the homeassistant container context, and what privileges are missing compared to the normal terminal window (where the script works) ?
Could it be, that the script is not even present in the context the shell_command is executed, and if yes, where would I have to place it?
Many thanks for any hints!