Different script response/behaviours from identical shell calls

hi folks,

I’ve got 2 directories which I’m trying to clean up by using a shell script service call.

Here are the 2 calls:

  clean_up_backup_files: '/usr/bin/find /backup/ -type f -mtime +10 -delete'
  clean_up_mpv_files: '/usr/bin/find /share/motioneye/ -type f -mtime +10 -delete'

The first call errors with no directory found.
The second call works as expected out-of-the box, and cleans the correctly found files away.

Here are the directories:

~ $ ls -ld /backup/ /config/ /share/motioneye/
drwxr-xr-x    2 root     root          4096 Dec 11 09:47 /backup/
drwxr-xr-x   11 root     root          4096 Dec 11 12:46 /config/
drwxr-xr-x    9 root     root          4096 Dec 11 09:41 /share/motioneye/
~ $ 

This is the error in the log file:

2022-12-11 12:48:00.321 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `/usr/bin/find /backup/ -type f -mtime +10 -delete`, return code: 1:
b'find: /backup/: No such file or directory\n'
2022-12-11 12:48:00.322 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/bin/find /backup/ -type f -mtime +10 -delete`, return code: 1
NoneType: None

It’s not clear to me how 2 virtually identical calls in virtually identical contexts are creating such a difference in behaviour. Maybe I’m missing something obvious?

I’m using:
Home Assistant 2022.12.1
Supervisor 2022.11.2
Operating System 9.3
Frontend 20221208.0 - latest

I don’t think the location of backup is where you think it is. What OS are you running?

hi Petro,
as per the OP:

Home Assistant 2022.12.1
Supervisor 2022.11.2
Operating System 9.3
Frontend 20221208.0 - latest

ah, missed that. I’m not 100% sure where it actually is on that os. I know it’s buried deep within a series of folders and samba exposes it as /backup/. Also, you might need to expose that folder for use in shell command via the homeassistant category in configuration.yaml.

1 Like

Ok, I’d forgotten I’d used media_dirs with /share/motioneye/, that might be the key. Looking…!

I should clarify, I’m going off memory here from reading other posts as I don’t use this OS

I was looking everywhere for it, as every post points to a different location, but it looks like it might be /root/backup/

$ find / -name backup
/root/backup
/backup

Nope, that’s not it, sigh. Ok, not going to complain about how complicated this has become to simply backup a directory of backups without using a mouse button. Just going to figure out some way to do it.

Thanks for your pointers, Petro!