我有一个无人值守的脚本来安装服务器。在脚本的开头有一个sudo apt-get dist-upgrade --yes。dist升级的末尾有一个讨厌的用户输入屏幕,要求重新启动服务:

是否可以自动接受服务重新启动或禁用此屏幕?它破坏了我的整个剧本。另外,我担心这可能会让我的服务器在更新时陷入困境.
apt-get升级的相同结果
编辑:我尝试了,但没有成功:
#!/bin/bash
sudo apt-get update
sudo apt-get remove apt-listchanges --assume-yes --force-yes &&
#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&
#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&
echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&
echo "executing autoremove" &&
sudo apt-get -fuy --force-yes autoremove &&
echo "executing clean" &&
sudo apt-get --force-yes clean &&
echo "executing update" &&
sudo apt-get update &&
echo "executing upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq upgrade &&
echo "executing dist-upgrade" &&
sudo apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuyq dist-upgrade发布于 2022-09-22 15:45:45
其他答案完全跳过了needrestart。
但是环境变量NEEDRESTART_MODE允许指定模式。通过选择“(A)自动”,您可以从needrestart中受益,而不会被提示阻止:
sudo NEEDRESTART_MODE=a apt-get dist-upgrade --yes发布于 2022-06-08 22:18:23
Vardogor的回答对我有效,只是有一个微小的差别,一个破折号(-y),而不是两个(--y):
sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y如果我使用两个破折号,就会产生这个错误:
E: Command line option --y is not understood in combination with the other options我在Ubuntu 22.04 LTS上做的
发布于 2022-12-06 16:24:09
或者,我认为您可以删除needrestart包本身。
sudo apt-get remove needrestart我将此用于Ubuntu22.04上的AWS EC2配置。无论出于什么原因,export DEBIAN_FRONTEND=noninteractive似乎都不起作用。
https://askubuntu.com/questions/1367139
复制相似问题