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

ghengalala
  • 109
  • 9
  • Assuming the command `mysql_secure_installation` is a script, check what it does and reimplement it in a non-interactive way. – Bodo Apr 06 '22 at 08: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. – Charles Duffy Apr 06 '22 at 12:38

1 Answers1

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

Alaindeseine
  • 3,260
  • 1
  • 11
  • 21
  • In [How to Answer](https://stackoverflow.com/help/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". – Charles Duffy Apr 06 '22 at 12:40