Shell_command in HASSIO

Does anyone know if it is possible to run shell_command services in hassio, with something like this:

find /backup -type f -mtime +4 -exec rm {} ;

It gives me this when run as a hass service:
Error running command: find /backup -type f -mtime +4 -exec rm {} ;, return code: 1
NoneType: None

It runs when I ssh in just fine. Tried a lot of variations, I’ve honestly lost track (su root -c, prepending with ‘bash’, etc). I’m starting to wonder if it has something to do with hass executing under some user other than root?

I had a similar issue. I can run this in ssh:

/usr/bin/mosquitto_sub -h sonoff.maddox.co.uk -t '#' -C 1

But as a command line sensor it fails.

I think in ssh it’s running in the host system but in a command line it’s running in the docker container or I might have them around the wrong way. In my case, one container or the other didn’t have the mosquitto_sub command available.

Just confirmed in WinSCP, the host doesn’t work as mosquitto_sub does not exist in the /usr/bin folder. The hass.io login ssh user DOES have it available.

In your case, I can see that /backup folder exists for the Hass.io user but in the host system I would use /usr/share/hassio/backup (which is the same folder)

Error running command: find /usr/share/hassio/backup -type f -mtime +4 -exec rm {} ;, return code: 1

10:56 PM /usr/local/lib/python3.6/site-packages/homeassistant/components/shell_command.py (ERROR)

Hmmm I’m still trying to wrap my head around all of this. Probably best to sleep and re-attack it tomorrow. :slight_smile:

I don’t know your exact setup but maybe you just can’t get access to that folder via the shell command. Also not sure if all ways of installing hass.io put the backup folder in the place I indicated…

If you have real access (ie you aren’t using the Raspberry Pi HassOS install) then have you thought about removing this from Home Assistant entirely and putting the command in a script and running a cronjob?

I was under the impression that cron/crontab don’t exist in the premade docker containers that HASSIO runs in. I poked around binaries and didn’t see them either.

Worst case I can get my phone to do it with tasker. It just seems odd that shell commands can’t operate on folders within the docker container of the thing that I’m SSHing too. Still poking at it though.

This was the method used for installation- https://www.home-assistant.io/hassio/installation/, on a raspi3.

Still appreciate any tips or ideas of stuff to try.

If you have real access to the OS ie not using HassOS or ResinOS then you can use cron. Nothing to do with pre-made docker containers or even docker at all.

I agree. As I said I ran afoul of this myself.

Did you make any progress with this ? I need to run exact same command on backup directory