gpt4 book ai didi

linux - 如何使用 commhe 和 line 为 whiptail 提供输入

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:40 26 4
gpt4 key购买 nike

因此,我必须设置多个服务器,每个服务器都需要 mysql-server。我决定编写一个 shell 脚本来输入 whiptail,这需要用户输入密码。我写了 bash 脚本,但是当它到达 whiptail 页面时它只是没有响应,任何人都可以帮我解决这个问题吗?谢谢

#!/bin/bash
sudo apt-get install mysql-server <<< "yes
mypassword
"

首先,当 sudo apt-get 询问是否安装时,它提供 yes,但是当它进入 whiptail 时,它不提供任何输入,因为它应该是 mypassword

enter image description here

最佳答案

无需向 whiptail 提供输入,您可以像这样运行 apt-get install 以在安装过程中跳过提示:

DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server

如果您还想提供 root 密码,您可以这样做:

export DEBIAN_FRONTEND="noninteractive"

sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password myrootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password myrootpw"

sudo apt-get install -y mysql-server

注意不要意外暴露您的 root 密码(即确保它不会出现在您的历史记录中,安全地删除任何包含它的脚本文件,我相信还有其他的)。

我找到了这个信息here .

关于linux - 如何使用 commhe 和 line 为 whiptail 提供输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43395751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com