2

For instance, when installing MySQL I would like to automatically run some commands and answer a few questions:

$ sudo mysql_secure_installation Enter current password for root (enter for none): Type root password Change the root password? N Remove anonymous users? Y Disallow root login remotely? Y Remove test database and access to it? Y Reload privilege tables now? Y 

I want to make a script that installs and automatically provides the answers to the configuration questions. How can I pass the MySQL configuration routine values based on set variables?

Edit[2015/04/18]:

Found a way:

echo -e "\npassword1\ny\npassword2\npassword2\ny\ny\ny\ny" | sudo /usr/bin/mysql_secure_installation 

Its a bit messy but works, but i think hek2mgl answer is more readable.

2
  • 2
    Please don't add "[Solved]" to the title. You indicated that problem has been solved by accepting an answer. Commented Apr 18, 2015 at 19:22
  • Ok sorry about that :) Commented Apr 19, 2015 at 0:34

1 Answer 1

1

You can write the answer into the command's stdin:

# Generate password somehow password="$(pwgen -S)" # Pass input to the installer using a here-document sudo mysql_secure_installation <<EOF $password N Y Y Y Y EOF 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.