Bash script in HassOS, return code: 1

Hi All,

This script I can run without errors on SSH inside de HassOS:

#!/bin/bash
sudo -u root docker exec -t addon_77b2833f_timescaledb pg_dumpall -c -U postgres > /root/share/dump_`date +%d-%m-%Y-%H_%M_%S`.sql

Created several possible options to create schell_commands:

postgres_backup1: "bash /share/postgres_backup.sh"
postgres_backup2: "bash -c /share/postgres_backup.sh"
postgres_backup3: "/bin/bash /share/postgres_backup.sh"
postgres_backup4: "/bin/bash -c /share/postgres_backup.sh"
postgres_backup5: "bash -c /share/postgres_backup.sh"

None of them are working see errors below:

2021-10-24 19:29:16 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash /share/postgres_backup.sh`, return code: 1
NoneType: None
2021-10-24 19:29:24 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash -c /share/postgres_backup.sh`, return code: 1
NoneType: None
2021-10-24 19:29:30 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash /share/postgres_backup.sh`, return code: 1
NoneType: None
2021-10-24 19:29:36 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash -c /share/postgres_backup.sh`, return code: 1
NoneType: None
2021-10-24 19:29:42 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash -c /share/postgres_backup.sh`, return code: 1
NoneType: None

What can I do to let this work?

command_line sensors run inside the HA docker container inside HassOS.
If you want to act on the OS side, you have to ssh to HassOS from the HA container.

I have HassOS 6.5 installed.
I need to do a dump from postgres. This is installed as addon in Home Assistant.

To understand you I need to ssh to my HA docker and then run the script?

Maybe easier to do this in the postgres docker itself if there is crontab as well. Then I can dump it to same shared folder

No, the command line must do an ssh to the OS to execute the script, something like:

fetch_ha_image:  >
  ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no [email protected] 'nohup sudo /usr/bin/docker pull homeassistant/raspberrypi4-homeassistant:stable > /dev/null 2>&1 &'
1 Like

Clear understand it now

I solved it other way.

In docker of postgres I did a crontab -e and it run the bash script now every 6 hours and the dump goes in /share/ so HA backup option can backup this folder also.