我想编写以下 Bash 脚本:
像这样安装 LAMP 时,它会询问我安装 MySQL 的 root 密码。 我想编写 bash 脚本。
sudo apt-get install lamp-server^
我可以这样将变量作为参数传递,这样它就不会在安装过程中询问我吗?
rootPassword="MyRootPassword";
sudo apt-get install lamp-server^ -y $rootPassword
最佳答案
为了以非交互方式回答 debconf 问题,您需要 debconf-utils 包。 debconf-set-selections 命令可用于将通常以交互方式询问的内容手动插入到 debconf 数据库中。这也可以在操作系统安装时使用 FAI 或预置来完成。
export DEBIAN_FRONTEND=noninteractive
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password select PASSWORD'
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password_again select PASSWORD'
您可能需要将 mysql-server 包名称更改为您的发行版使用的版本。请注意,包“mysql”是一个虚拟包,它指向真实包(包括版本号)。
关于mysql - 使用预定义的 root 密码安装脚本 LAMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8648828/