Skip to content

jermsmit/ubuntu-auto-update

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

ubuntu-auto-update

Automated weekly update script for Ubuntu servers — fully unattended with logging.

A simple, reliable bash script that handles the complete Ubuntu update cycle and logs everything. Set it once via cron and your servers stay patched automatically.

Ubuntu License Shell


What It Does

Runs the full Ubuntu update cycle in sequence:

  1. apt-get update — refreshes package lists
  2. apt-get dist-upgrade — installs all available upgrades including kernel updates
  3. apt-get clean — removes cached package files
  4. apt-get autoclean — removes outdated cached packages
  5. apt autoremove --purge — removes unused dependencies
  6. reboot — reboots to apply any kernel or system updates

All output is logged to /var/log/weekly-update.log with timestamps.


Installation

1. Download the script

wget https://raw.githubusercontent.com/jermsmit/ubuntu-auto-update/main/weekly-update.sh

2. Move it to a system location

sudo mv weekly-update.sh /usr/local/sbin/weekly-update.sh

3. Make it executable

sudo chmod +x /usr/local/sbin/weekly-update.sh

4. Schedule it with cron

sudo crontab -e

Add this line to run every Sunday at 2:00 AM:

0 2 * * 0 /usr/local/sbin/weekly-update.sh

Viewing Logs

# View the full log
cat /var/log/weekly-update.log

# Watch live during a run
tail -f /var/log/weekly-update.log

# View only the last run
grep -A 100 "$(grep 'Update started' /var/log/weekly-update.log | tail -1)" /var/log/weekly-update.log

Notes

  • Script must be run as root (or via sudo cron) to perform system updates and reboot
  • The reboot at the end ensures kernel updates are applied — remove the last line if you prefer manual reboots
  • Suitable for Ubuntu 20.04, 22.04, and 24.04 LTS
  • Log file grows over time — consider adding logrotate if running long term

Optional: Log Rotation

To prevent the log file growing indefinitely, create a logrotate config:

sudo tee /etc/logrotate.d/weekly-update << 'EOF'
/var/log/weekly-update.log {
    monthly
    rotate 6
    compress
    missingok
    notifempty
}
EOF

License

MIT — free to use, modify, and distribute.

About

Automated weekly update script for Ubuntu servers — fully unattended with logging

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages