pepeEL
(pepeEL)
March 21, 2019, 11:56am
1
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.
pepeEL
(pepeEL)
March 21, 2019, 12:02pm
3
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.
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'
pepeEL
(pepeEL)
March 21, 2019, 12:28pm
9
Yes it is virtualenv on Hassbian.
pepeEL
(pepeEL)
March 21, 2019, 12:32pm
10
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.
pepeEL
(pepeEL)
March 21, 2019, 1:04pm
12
jackwilsdon:
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
pepeEL
(pepeEL)
March 21, 2019, 1:19pm
14
but please explaine me more…
pepeEL
(pepeEL)
March 21, 2019, 8:34pm
16
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.
pepeEL
(pepeEL)
March 21, 2019, 9:45pm
18
But in other shell command use Hass and works?
pepeEL
(pepeEL)
March 22, 2019, 6:41am
19
i found this thread and in this show that user name is hass
@StormStrikes what you would do is create a script owned by root, in your case this rsync script, then you add a sudoers line like this:
user hass = (root) NOPASSWD: /foo/bar/rsyncscript
This way the hass user can call sudo /foo/bar/rsyncscript and NOTHING ELSE. Since the script is owned by root, the root user is the only one who can modify the script (make sure it’s permissions are 755 and you’ll be fine).
FYI, don’t edit sudoers manually (or copying from another host like you did, since su…
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.