Hi All,
I am trying to automate a github backup with a shell script.
I can run my shell script file with no issues from a terminal (both with ssh and in the ‘Terminal & SSH’ addon). but, when I run through an automation I receive an error ’ Error running command: bash ha_gitpush.sh, return code: 128’
#ha_gitpush.sh
# Go to /config folder or
# Change this to your Home Assistant config folder if it is different
cd /config
# Add all files to the repository with respect to .gitignore rules
git add .
# Commit changes with message with current date stamp
git commit -m "config files on `date +'%d-%m-%Y %H:%M:%S'`"
# Push changes towards GitHub
git push -u origin master
OK - could you please help me think through this? The public SSH key is located on my Home Assistant (RPi). Are you asking me to set up this script (setup venv, setup a new ssh key, run the script, etc.) from another computer with venv?
What do you mean the SSH key is located? Basically on another computer that hasn’t been set up with Git auth / credentials, or a venv, try running your script.
When you SSH into HA you’re actually ssh’ing into an add-on which is a different docker container from HA itself. Each docker container has its own filesystem and installed packages, successfully running it while ssh’ed really doesn’t tell you anything about whether it will work when run from HA.
all above was right, but I had to open a console of HA execute the following command (thanks @VDRainer!):
docker exec -it homeassistant bash
then run the shell script (which was already working in the regular terminal)
bash /config/ha_gitpush.sh
the system then asks me to put github.com to the list of konwn hosts.
After that, the shell script worked again, while starting to a HA-automation.
But it wasn’t resistant because of:
Normally you just go through this once and then you are good to go, it never prompts you to verify authenticity again. However with HA this is another gotcha. The problem is that by default the known_hosts file is stored in /root/.ssh . Which means if you stop here your sensor will appear to work but will break next update when /root is wiped clean.
in order to set the proposed ssh option -o UserKnownHostsFile=... to git. I used this command: