I download files to Home Assistant’s /media
directory and have some shell scripts that organise and delete files.
I’m currently running the supervised installation of Home Assistant within Ubuntu on an Intel NUC. Home Assistant has a shell command that calls a script on the host (the NUC) via SSH:
shell_command:
tidy_media: ssh my-intel-nuc.local -F /config/.ssh/config 'bash ~/scripts/tidy-media.sh'
The shell script then accesses the exposed /media
folder from within Home Assistant to perform the commands:
#!/bin/bash
cd "/usr/share/hassio/media"
echo "I am in the /media directory"
# more stuff, tidying media etc.
# rm downloads/file_name.txt
# mv downloads/file_name.txt /files/file_name.txt
This works, but it’s a bit crazy to be SSHing out to the host to run a script that just calls back in to Home Assistant. I’d like to switch to a Home Assistant OS setup and remove Ubuntu from the equation, so I need to run these scripts entirely within Home Assistant.
To do this, I’ve moved the script in to Home Assistant’s config and as-per the docs setup my shell command like this:
shell_command:
tidy_media: bash /config/shell/tidy_media.sh
If I run bash /config/shell/tidy_media.sh
from the terminal in the VSCode addon (which looks to run as root
) the script executes correctly.
However if I call the command from the Home Assistant UI I get this error in my logs:
Error running command: `bash /config/shell/tidy_media.sh`, return code: 1
return code: 1
looks to be an authorisation error. So when the script is called from Home Assistant it’s not running as root
but some other user, that doesn’t have permission to modify files within the /media
directory.
Does anyone have any ideas on a fix for this? I want to run a script from within Home Assistant’s config directory that modifies files in the nearby official Home Assistant /media
directory.
I’ve tried changing permissions from the terminal in the VSCode addon but it seems to make no difference. Besides such permissions are likely to be reset, and shouldn’t be necessary given what I’m trying to do?