Hi all,
I'm using CHEF to automate the environment of my VPS.
My wish is now to create a MySQL user.
To prevent passing the MySQL-password as a command line arg I'm using /usr/bin/expect.
This seems to be more complicated than I thought.
Without CHEF and expect I would to:
Code:
mysql -uroot -p
[password]
MariaDB [(none)]> CREATE USER `test123`@`localhost` IDENTIFIED BY 'some_pass';
My CHEF recipe looks like this (I've removed the CHEF variables and substituted the username and password):
Code:
bash "create-mysql-user" do
user "root"
code <<-EOF
/usr/bin/expect -c 'spawn mysql -uroot -p
expect "Enter password: "
send "root_password"
expect "MariaDB*none*>*"
send "CREATE USER `test123`@`localhost` IDENTIFIED BY 'some_pass';\r"
expect EOF'
EOF
end
This produces: ERROR 1064 (42000): You have an error in your SQL syntax;....
Going through the log I see, that the single quotes around the passwords get removed.
Now: Whatever I tried, I couldn't get the single quotes in the final output.
I tried:
- ... to escape them with \'
- ... to writhe the single quotes twice: ''some_password''
So my question is: How can I use /usr/bin/expect with "-c" AND single quotes?
Thanks in advance and best regards