Ubuntu: Remote installation of mysql got stuck



Question:

I have written a script to install some set of packages to a list of servers. When i execute the script mysql installation got stuck at "enter the root password" section. Is there anything i need to modify in my script ? Advice me.

Is there any way to pass the mysql root password through the script itself ?

#!/usr/bin/env bash  Servers_list=/opt/servers_list  for Host in $(< $Servers_list )  do  echo "Installing package on $Host"  #ssh "${Host}" apt-get -y install "${PackageName}"  ssh "${Host}" apt-get update $$ apt-get -y install apache2 apache2-doc apache2-utils mysql-server  done  

The password screen is different and it stuck here

The usual password config window for mysql setup


Solution:1

Try this :

#!/usr/bin/env bash  Servers_list=/opt/servers_list  for Host in $(< $Servers_list )  do    echo "Installing package on $Host"    ssh "${Host}" "echo 'mysql-server-5.7 mysql-server/root_password password your_password' | debconf-set-selections && \        echo 'mysql-server-5.7 mysql-server/root_password_again password your_password' | debconf-set-selections && \        apt-get update && \        apt-get -y install apache2 apache2-doc apache2-utils mysql-server"  done  

If you have a lot of server you should consider using a tool like ansible or puppet.

Edit :

  • Backslash (\) are used for readability. They allow to continue the command on a next line.
  • AND (&&) operator is used to exec many command on the same line. If one fail the next is not executed.
  • debconf-set-selections is used to preset configs. In this case : password. You can find more information on it inside the man page by typing : man debconf-set-selections inside terminal.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »