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 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)
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.
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.