0

I am crating a script to deploy an application which requires me to install mysql. now first command that i need to run is

apt install mysql-server

This has a y/n prompt which i can handle with -y flag but after this i need to run the following command

mysql_secure_installation 

This command asks user for multiple inputs like

validate password Y/n prompt, 
password strength 0/1/2, 
password, 
repeat password, 
continue with password y/n, 
delete anonymous users y/n, 
disallow remote root login y/n, 
remove test database y/n, 
reload previlidge tables y/n

Is there a way that i can specify all the options in the script

2
  • Assuming the command mysql_secure_installation is a script, check what it does and reimplement it in a non-interactive way. Commented Apr 6, 2022 at 8:22
  • Better scripts will already provide a way to override them. Read its source code -- if it's well-written it'll prompt the user only if the information isn't set by command-line arguments or environment variables. And if it isn't well-written now, consider writing a patch to provide to the project that makes it. Commented Apr 6, 2022 at 12:38

1 Answer 1

0

You can create a txt file with responses and pass it to your interactive command, like this:

/path/to/my/command << commands.txt

You can also use expect command: https://linux.die.net/man/1/expect

Sign up to request clarification or add additional context in comments.

1 Comment

In How to Answer, note the section Answer Well-Asked Questions and the bullet point regarding questions "that have been asked and answered many times before".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.