Ubuntu 自动安装 sh 脚本,如何将 apt-get 或其他命令的答案传递给配置选项?
Ubuntu auto-install sh script, how to pass apt-get or other commands answers to config options?
例如,在安装 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 答案更具可读性。
您可以将答案写入命令的标准输入:
# 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
例如,在安装 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 答案更具可读性。
您可以将答案写入命令的标准输入:
# 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