unattended-upgrades能够自动更新系统,但是要配置一堆东西,对新手而言门槛很高。反正内容也不多,核心的apt update && apt upgrade -y加上crontab定时任务就能实现,索性自己写了一个安装脚本,实现Debian系的自动更新。

AutoUpgrade的Github地址:https://github.com/uselibrary/AutoUpgrade

使用root权限执行以下脚本即可。安装过程中将询问是否需要更新后提醒功能,若输入“N”则不会提醒;若输入“Y”,则需要输入电报机器人的token和chat id,更新后将通过电报机器人进行提醒。

wget --no-check-certificate -O AutoUpgradeInstall.sh https://raw.githubusercontent.com/uselibrary/AutoUpgrade/main/install.sh && chmod +x AutoUpgradeInstall.sh && bash AutoUpgradeInstall.sh

如果选择提醒,输入"y"后如下,需输入电报机器人的token和chat id
enable_notification.jpg

如果不需要提醒,输入"n"后如下,则自动完成安装
disable_notification.jpg

电报机器人的提醒如下,有更新的软件数量和更新的时间。
telegram_bot_notification.jpg

文件位于/usr/local/AutoUpgrade/中,其中AutoUpgrade.sh为脚本,使用crontab实现每天凌晨3点进行检查更新,upgrade.log为日志,包含更新的时间和内容。日志内容实例如下:

2022-06-02 03:00:42
Listing...
dpkg/stable-security 1.20.10 amd64 [upgradable from: 1.20.9]
gzip/stable-security 1.10-4+deb11u1 amd64 [upgradable from: 1.10-4]
liblzma5/stable-security 5.2.5-2.1~deb11u1 amd64 [upgradable from: 5.2.5-2]
libssl1.1/stable-security 1.1.1n-0+deb11u2 amd64 [upgradable from: 1.1.1n-0+deb11u1]
linux-image-amd64/stable-security 5.10.113-1 amd64 [upgradable from: 5.10.106-1]
rsyslog/stable-security 8.2102.0-2+deb11u1 amd64 [upgradable from: 8.2102.0-2]
tzdata/stable-updates 2021a-1+deb11u3 all [upgradable from: 2021a-1+deb11u2]
zlib1g/stable-security 1:1.2.11.dfsg-2+deb11u1 amd64 [upgradable from: 1:1.2.11.dfsg-2]

标签: linux

添加新评论