Error 1064 (42000) syntax sql error

0

I have the following line of code in a bash script.

echo password | sudo -S su -l otrouser -c 'mysql  -e "GRANT ALL ON wordpress.* to 'usuario'@'localhost' IDENTIFIED BY 'userpass';"'

I want to execute the mysql statement as another user. If I execute the statement directly in the mysql console, it executes it without problems. I do not know if it can be a problem of single quotes, double quotes or too many nested commands.

Thank you .-

    
asked by sfr 06.02.2018 в 16:54
source

1 answer

1

My advice is that you create the script using sudo in a normal way (without echo ) and then you give permissions of sudo without password:

Edit /etc/sudoers with the visudo command and give your user the NOPASSWD permission to your script:

<nombre_de_usuario> ALL=(ALL) NOPASSWD: /opt/mi-script.sh

That way, if you do "sudo" in that script, you will have immediate access to the requested user without a password.

    
answered by 06.02.2018 в 18:06