我正在一个Dockerfile中工作,但是我需要运行一个“安全”的MariaDB服务器脚本,它是交互式的,我不知道如何处理这个问题。
基本上,这是我在测试环境中对脚本所遵循的流程,也是我希望在没有用户交互的Dockerfile中实现的流程,只需回答下面的流程:
# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): [ENTER] // because there is no password
OK, successfully used password, moving on...
Set root password? [Y/n] n
... skipping.
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] n
... skipping.
Remove test database and access to it? [Y/n] Y
- 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] Y
... Success!
Cleaning up...所以我需要写一个bash脚本或者其他什么东西来自动处理这个问题,但是你不知道,你会怎么处理这个呢?
发布于 2016-01-29 14:17:03
我认为你可以尝试两种不同的方法:
expect脚本最终从bash“计算”。手册页这里或者:
**编辑-备选案文2 **示例
#!/bin/bash
...
/usr/bin/mysql_secure_installation <<EOF
n
Y
n
Y
Y
EOF
...基本上,您将所有答案传递给mysql_secure_installation的标准输入。
使用expect要复杂一些。你可以从这里开始
发布于 2016-01-29 14:50:19
另一个选项,mysql_secure_installation是一个简单的bash脚本,它执行多个mysql命令,只需使用sql命令即可。
DELETE FROM mysql.user WHERE User='';
DROP DATABASE test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;将这些命令保存在一个文件中,并将其输送到mysql。
mysql < my_file.sqlhttps://stackoverflow.com/questions/35086438
复制相似问题