Shell command problem, commaands in terminal works, in automation not

I’m trying to copy files from a subdir of the /backup dir under Home Assistant OS to a directory on a mounted usb drive.

These are the shell commands:

create directory on mounted drive

mkdir -p /media/DATEN/openccu

copy only the last 3 files

ls -t /backup/openccu | head -n 3 | xargs -I{} cp -f /backup/openccu/{} /media/DATEN/openccu/

delete all files older than 10 days

find /media/DATEN/openccu -type f -mtime +10 -delete

When typing these commands into the HA terminal all works fine.
Calling the script from automation only create the folder on the mounted drive.

What is the problem ?

Did you try this integration?

or

It’s customary to share the YAML for what you’ve tried, along with any errors that appear in your logs.

Since you’re asking us to throw darts while blindfolded, I’m going to guess it’s a directory access issue. See allowlist_external_dirs

1 Like

Yes I tried shell_command in configuration.yaml but that didn’t work like the shell file.
Think It is a problem of the “seeing” the /backup/ directory in terminal or in automations.
The automations part has more restrictions and the /backup dir is not accessible for automations. So I hoped I could solve it with a script file, but it has the same problem.

You could try reading the other reply this thread

when using

homeassistant:
  allowlist_external_dirs:
    - /media
    - /backup

I get the error:
Invalid config for ‘homeassistant’ at configuration.yaml, line 49: Not a directory ‘allowlist_external_dirs->1’, got ‘/backup’

So this will not work for /backup

Is it not the config subfolder? I run container, and backups is plural, so for me it is /config/backups

I’m not sure what it should be for HAOS

Remember the terminal is not the same environment that an HA shell command executes in.

The HA shell commands execute inside the HA docker container.

Whereas terminal command execute in the shell in HAOS which hosts the docker container.

1 Like

It looks like there is no way for me to “see” the /backup dir in automations under HAOS.
I use openccu, that create a backup at midnight in the /backup/openccu dir. It is possible to change the backup path in it, I tried /shares/openccu, but the openccu could not see it.