Having a script call a shell command

I have a shell command that uses rclone to backup my configs to an encrypted GDrive folder. The script works fine, I also have a cron job of it that works fine. However I also want the ability to call it manually in home assistant.

In my configuration.yaml I have:

  backup_configs_rclone: /bin/bash -c /home/homeassistant/.homeassistant/shell_scripts/rclone-cron.sh

And then I have a script:

   alias: 'Config Backup'
    - service: shell_command.backup_configs_rclone

When I run it in home assistant I get this:

Error running command: /bin/bash -c /home/homeassistant/.homeassistant/shell_scripts/rclone-cron.sh, return code: 1

Not sure what Iā€™m missing.

The fIrst thing to check is that user homeassistant has execute permission on the script and write permissions where you want to put the result.

1 Like

The same happen to me with this binary_sensor:

  - platform: command_line
    name: Mosquitto
    command: sudo systemctl status mosquitto.service | awk 'FNR==3 { print $3 }'
    device_class: connectivity
    payload_on: "(running)"
    payload_off: "(dead)"

So, as @gpbenton writes, how to check if user homeassistant has permissions to execute this command?

The simplest way is to try and run the command as homeassistant user, within the virtual environment if you have one set up. Alternatively, use the command line command ls -l to display the permissions on files and directories.

But in your case, as I said in the other thread, user homeassistant does not have sudo permissions, so that command will not run. Fortunately for you, systemctl status does not need sudo permissions and you can change the command to

    command: systemctl status mosquitto.service | awk 'FNR==3 { print $3 }'