【问题标题】:Ubuntu auto-install sh script, how to pass apt-get or other commands answers to config options?Ubuntu 自动安装 sh 脚本,如何将 apt-get 或其他命令答案传递给配置选项?
【发布时间】:2015-06-25 08:12:20
【问题描述】:

例如,在安装 MySQL 时,我想自动运行一些命令并回答几个问题:

$ sudo mysql_secure_installation
Enter current password for root (enter for none): Type root password
Change the root password? N
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y

我想制作一个脚本来安装并自动提供配置问题的答案。如何根据设置的变量传递 MySQL 配置例程值?

编辑[2015/04/18]:

找到了一条路:

echo -e "\npassword1\ny\npassword2\npassword2\ny\ny\ny\ny" | sudo /usr/bin/mysql_secure_installation

它有点凌乱但有效,但我认为 hek2mgl 答案更具可读性。

【问题讨论】:

  • 请不要在标题中添加“[已解决]”。您表示通过接受答案已解决问题。
  • 好吧,抱歉 :)

标签: linux bash shell ubuntu apt-get


【解决方案1】:

您可以将答案写入命令的标准输入:

# Generate password somehow
password="$(pwgen -S)"

# Pass input to the installer using a here-document
sudo mysql_secure_installation <<EOF
$password
N
Y
Y
Y
Y
EOF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 2018-07-21
    • 2022-11-14
    • 2012-12-10
    • 1970-01-01
    • 2018-03-27
    • 2016-05-06
    • 1970-01-01
    相关资源
    最近更新 更多