启动时无法获取更新脚本

启动时无法获取更新脚本

我正在没有桌面环境的 Debian 9.7.0 上工作。我制作了一个脚本来更新我的软件包,并添加到 /etc/crontab 中以在启动时运行。这是脚本:

#!/bin/bash
apt-get update && apt-get upgrade

当我手动运行它时,它工作得很好,但在启动时 apt-get 不会获取 debian url。这是日志:

Err:1 http:///ftp.be.debian.org/debian stretch InRelease
  Temporary failure resolving 'ftp.be.debian.org'
Err:2 http://ftp.be.debian.org/debian stretch-updates InRelease
  Temporary failure resolving 'ftp.be.debian.org'
Err:3 http://security.debian.org/debian-security stretch/updates InRelease
  Temporary failure resolving 'security.debian.org'
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

如果我没记错的话 apt-get 无法访问 debian 服务器?

编辑:我也尝试更改 /etc/apt/sources.list 中的服务器,但仍然出现相同的错误。

有人知道如何发生以及如何处理它吗?

我找不到任何答案,所以希望这不是转发。祝你有美好的一天。

答案1

看起来这个脚本是在网络启动之前运行的。

我建议使用systemd将在启动时运行的服务,这样可以要求它在网络启动后运行。

例如:

# /etc/systemd/system/update.service
[Unit]
Description=Apt Update & Upgrade
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
KillMode=process
ExecStart=/usr/local/bin/update-script

[Install]
WantedBy=multi-user.target

然后运行:

systemctl daemon-reload
systemctl enable update.service

或者,我可能会使用该unattended-upgrades包来完成所有这些工作。

相关内容