是的,我知道无人值守升级,但我不喜欢该软件包的限制。我有一个 PHP 脚本,可以进行以下调用:
...
system("/usr/bin/apt-get update");
system("/usr/bin/apt-get -y upgrade 2>&1 > /tmp/apt_get.txt");
system("/usr/bin/apt-get autoremove");
system("/usr/bin/apt-get autoclean");
...
该脚本通过 cron 设置为按计划自动运行。它似乎以 root 身份正确执行了所有命令。但是,“apt-get -y Upgrade”实际上并不执行升级,如 /tmp/apt_get.txt 的输出所示:
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be upgraded:
iproute
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 444 kB of archives.
After this operation, 1,024 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main iproute amd64 20111117-1ubuntu2.3 [444 kB] Fetched 444 kB in 1s (374 kB/s)
手动运行“apt-get升级”显示软件包已下载但未安装:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
iproute
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/444 kB of archives.
After this operation, 1,024 B of additional disk space will be used.
Do you want to continue [Y/n]? n
Abort.
因此 apt-get 成功下载了软件包,但并未实际执行升级。我需要更改什么才能使该脚本按预期工作?它几乎看起来像是“apt-get -y update”本身的一个错误。 (此处运行 Ubuntu 12.04.4 LTS。)
答案1
我假设它询问是否覆盖/保留/比较编辑的配置文件。在这种情况下,您需要添加 DEBIAN_FRONTEND=noninteractive。
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade