2

Quiero conseguir que al ejecutar un script Bash e instalar MySQL, poder responder de forma 'unattended' a las preguntas del comando 'mysql_secure_installation'.

La secuencia sería : Enter, n, n, y, y, y, y

1 respuesta 1

3

Una posible solución es escribir la secuencia de "y" / "n" y pasarla a mysql_secure_installation con un pipe:

echo -e "\nn\nn\ny\ny\ny\ny\n" | mysql_secure_installation 

Cada vez que presionas Enter se traduce en \n

Y aquí la comprobación:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

stty: 'entrada estàndard': L’operació ioctl() no s’adequa al dispositiu
Enter current password for root (enter for none): 
stty: 'entrada estàndard': L’operació ioctl() no s’adequa al dispositiu
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]  ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]  ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]  ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]  - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]  ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
root@gil-NUC10i7FNH:~# 

(he cambiado el idioma de la consola para que saliera en español pero no ha sido posible)

5
  • Funciona perfectamente. Por cierto, no me ha quedado claro pero había entendido que había que darle a Enter para cada opción, no se si he entendido mal. Pero yo he escrito el comando y lo ha ejecutado de forma totalmente unattended, apto para usar en un script Bash como quería sin ningún tipo de intervención. el 16 mar. 2021 a las 21:19
  • 1
    Cuado tu le as a Enter, se traduce en un "\n", solo eso.
    – gilito
    el 16 mar. 2021 a las 21:22
  • Perdona, sabes si el error stty: 'standard input': Inappropriate ioctl for device es algo importante? O lo puedo pasar por alto? el 16 mar. 2021 a las 21:34
  • Asi de buenas a primeras, ni idea... Abre una nueva pregunta pero explicando el contexto en que te sale eso....
    – gilito
    el 16 mar. 2021 a las 21:37
  • El contexto en el que me sale eso es en el de esta pregunta. Es el mismo mensaje que te sale a ti supongo que en italiano. Cuando dice de poner una contraseña o darle a Enter para dejarlo en blanco. No entiendo por que debería abrir otra pregunta. De todos modos te agradezco la ayuda y lo dejo aquí, ya que parece funcionar a pesar de ese error. el 16 mar. 2021 a las 21:50

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.