Script for creating backup - Not working

Hi
I create in location /home/homeassistant/.homeassistant/HA_backup_system.sh this script with privalages 0777 for owner homeassistant:

#!/bin/bash
sudo mount -t cifs -o username=USERNAME,password=PASSWORD //192.168.xx.xx/Backup/Home_Assistant /mnt/Backup
NOW=$(date +"%Y%m%d_%H%M");
sudo dd bs=2M if=/dev/sda of=/mnt/Backup/HA_backup_$NOW.img
sudo umount //192.168.xx.xx/Backup/Home_Assistant

then in shell command in Home assistant add:

backup: ‘echo [hass password] | /home/homeassistant/.homeassistant/HA_backup_system.sh >> /home/homeassistant/.homeassistant/Logs_scripts/backup/backup-date +%Y%m%d-%H%M.log’

Next in GUI HA i create script:
‘1552384920506’:
alias: HA_backup_system
sequence:
- data: {}
service: shell_command.backup

But when run this script in HA only create file date.log and nothing else…
Please help me. When run script /home/homeassistant/.homeassistant/HA_backup_system.sh from putty by user pi on raspberry all works ok.

Where did you get the script? I am not familiar with it.

I create this script. But it works from putty comanf line.

Please post the contents of the script, using the instructions at the top of this page to format it correctly.

corrected :slight_smile:

Is this a virtualenv Home assistant installation?

Does sudo require you to enter the user password?

Try redirecting stderr to the log too and see if there’s any new output;

backup: 'echo [hass password] | /home/homeassistant/.homeassistant/HA_backup_system.sh >> /home/homeassistant/.homeassistant/Logs_scripts/backup/backup-date +%Y%m%d-%H%M.log 2>&1'

Yes it is virtualenv on Hassbian.

When run write in log this:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

So yeah it’s trying to run sudo and doesn’t know how to ask for a password (because it’s running without stdin), your best bet is to enable passwordless sudo for the user for that specific script. I don’t know how to do it off the top of my head but there’s documentation online on allowing passwordless sudo for a specific executable.

I also use other shell command:
update: ‘echo [hass password] | /home/homeassistant/.homeassistant/updateHA.sh >> /home/homeassistant/.homeassistant/Logs_scripts/update/update-date +%Y%m%d-%H%M.log’

with this sh:
#!/bin/bash

sudo hassbian-config upgrade homeassistant

and it works ok.

There is a way of configuring sudo to not ask for a password.

https://www.sudo.ws/man/1.8.15/sudoers.man.html

but please explaine me more…

i added to sudoers at the end this line:

hass ALL=(ALL) NOPASSWD:ALL

and also not working… Run script in HA but backup is not done.

is hass your username? I though the default user was homeassistant.

But in other shell command use Hass and works?

i found this thread and in this show that user name is hass

But when add user homeassistant to sudoers all works ok.
But i add this:
homeassistant ALL=(ALL) NOPASSWD:ALL

But how i can add only to have sudo to only one script ? Now has to all sudo access.