Shell_command throws error when run from automation , but not from services

This is really strange.
I can successfully call shell_command from “service” and it works, but when i ran it from automation it fails, that it cannot find folder.

Fail:

DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `curl -T /backup/$(ls -t /backup/ | head -n 1) -u ****:**** ftp://192.168.1.15//mnt/Hassio_Backup/`, return code: 26:
b"curl: Can't open '/backup/New'!\ncurl: try 'curl --help' or 'curl --manual' for more information\ncurl: (26)

Works:

DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `curl -T /backup/$(ls -t /backup/ | head -n 1) -u ****:**** ftp://192.168.1.15//mnt/Hassio_Backup/`, return code: 0:

Command is:

shell_command:
    ftpbackup_lastfile3: 'curl -T /backup/$(ls -t /backup/ | head -n 1) -u ****:**** ftp://192.168.1.15//mnt/Hassio_Backup/'

Automation:

- id: 'ftpbackup'
  alias: 'ftp backup'
  trigger:
    platform: event
    event_type: folder_watcher
    event_data:
      event_type: created
  action:
     service: shell_command.ftpbackup_lastfile4

Is there a difference of how shell is called from automation and service in Hassio?

EDIT: I should add that i mapped and whitelisted Backup folder to Hassio by editing docker config if that makes any difference .

EDIT 2: SOLVED - i had to add a delay in automation as folder_watcher triggers script to quickly while file is not completely created.

I think yes but I not good person to confirm this.

I do know I had similar issue. Basically json wasn’t allowed for me. Ultimately I changed to rest_command and called the created rest service in automations and had no issue.

Hi @asouthernboy,
I am trying to do the same, except that I will use an event from the auto-backup community integration instead of the folder watcher, but I can’t get the shell command running, always getting return code 26.
Had you to set ‘/backup’ in the white list of external directories in the config? I can’t get it working (error in config, not a directory). What am I missing?
Thanks!

1 Like

You’re missing that Backup folder is not exposed to Home Assistant and “whitelisting” wont do anything.

I edited docker config json file,but it’s not recommended, as it will be reset on every upgrade or eventually mess up with your system.

Currently there’s no easy or good solution to this

That’s what I feared, but hoped you had found a magical solution (or I would have missed a recent development on this issue). I had found related issues in Github, but left open and apparently abandoned. Let’s hope this issue of not exposing this folder will surface again soon.
Thanks for your reply anyway.

I have the same exact issue, seems like many folders not shown when you run shell_command.

2020-07-14 16:02:05 DEBUG (MainThread) [homeassistant.components.shell_command] Stdout of command: `mount -a;df -kh`, return code: 0:
b'Filesystem                Size      Used Available Use% Mounted on
overlay                  27.2G      2.6G     23.2G  10% /
tmpfs                    64.0M         0     64.0M   0% /dev
tmpfs                     1.9G         0      1.9G   0% /sys/fs/cgroup
shm                      64.0M         0     64.0M   0% /dev/shm
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /ssl
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /config
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /share
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /etc/asound.conf
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /run/audio
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /etc/resolv.conf
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /etc/hostname
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /etc/hosts
/dev/mmcblk0p8           27.2G      2.6G     23.2G  10% /etc/pulse/client.conf