Managing /media with shell scripts

@ondras12345 thank you for your reply! I stupidly assumed return code: 1 was all I could get, I hadn’t tried outputting the error to a file.

Being able to see the full error using command &> error.txt revealed some issues with my script, for example find doesn’t seem to have the -execdir option when the script is called from the Home Assistant UI, but it does have -exec which avoided these errors and even the rm command seems to work.

Another solution I was considering before your reply was passing the script to the “SSH & Web Terminal” add-on which runs with more permissions, like this. Thankfully this hasn’t been necessary though.

In the end, very simple working setup:

/config/configuration.yaml

shell_command:
  tidy_media: bash shell/tidy_media.sh

/config/shell/tidy_media.sh

#!/bin/bash

rm /media/useless_file.txt

Thanks again!

1 Like