Essayez ceci tel quel, il semble qu'il y ait un problème avec (
et le pipe |
donc j'ai dû les échapper.
Code source
#!/bin/bash
MYSQL=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $11}')
MYSQL_ROOT_PASSWORD="test@123"
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect "Enter password for user root:"
send "$MYSQL\r"
expect "Change the password for root ?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect "New password:"
send "$MYSQL_ROOT_PASSWORD\r"
expect "Re-enter new password:"
send "$MYSQL_ROOT_PASSWORD\r"
expect "Do you wish to continue with the password provided?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect "Remove anonymous users?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect "Disallow root login remotely?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect "Remove test database and access to it?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect "Reload privilege tables now?\(Press y\|Y for Yes, any other key for No\) :"
send "y\r"
expect eof
")
echo "$SECURE_MYSQL"
Exécution de débogage
root@5015a2757ac4:/# bash -x secure.sh
++ grep 'temporary password' /var/log/mysqld.log
++ awk '{print $11}'
grep: /var/log/mysqld.log: Aucun fichier ou dossier de ce type
+ MYSQL=
+ MYSQL_ROOT_PASSWORD=test@123
++ expect -c '
set timeout 10
spawn mysql_secure_installation
expect Enter' password for user 'root:
send r
expect Change' the password for root '?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect New' 'password:
send test@123r
expect Re-enter' new 'password:
send test@123r
expect Do' you wish to continue with the password 'provided?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect Remove' anonymous 'users?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect Disallow' root login 'remotely?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect Remove' test database and access to 'it?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect Reload' privilege tables 'now?(Press' 'y|Y' for Yes, any other key for 'No)' ':
send yr
expect eof
'
couldn't read file "password": no such file or directory
+ SECURE_MYSQL='spawn mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: '
+ echo 'spawn mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: '
spawn mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
root@5015a2757ac4:/#
Et j'ai vérifié la connexion avec le nouveau mot de passe test@123
.