Skip to content

Instantly share code, notes, and snippets.

@aoaim
Created November 21, 2024 06:21
Show Gist options
  • Select an option

  • Save aoaim/d6f3dd0923c560fb6988ee515a914be7 to your computer and use it in GitHub Desktop.

Select an option

Save aoaim/d6f3dd0923c560fb6988ee515a914be7 to your computer and use it in GitHub Desktop.
设置debian自动更新
#!/bin/bash
# 1. 创建脚本文件 /root/apt-update.sh
echo '#!/bin/bash' | sudo tee /root/apt-update.sh > /dev/null
echo 'apt update && apt upgrade -y && apt autoremove -y' | sudo tee -a /root/apt-update.sh > /dev/null
# 2. 自动在 crontab 最后添加任务
(crontab -l; echo '0 */12 * * * /root/apt-update.sh') | sort - | uniq - | crontab -
# 3. 赋予权限
sudo chmod +x /root/apt-update.sh
# 4. 测试定时任务是否能正常运行
echo "Testing the scheduled task..."
/root/apt-update.sh
# 5. 最后执行一次 apt update && apt upgrade -y && apt autoremove -y
echo "Executing the update and upgrade..."
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
echo "Setup completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment