🔄 Automate Monthly System Updates on Ubuntu 24.04
A simple, reliable way to keep your Ubuntu‑based VPN server fully updated.
This guide shows you how to create an update script, schedule it to run monthly, optionally reboot afterward, and verify everything is working.
📝 Step 1: Create the Update Script
First, create the script file:
sudo nano /usr/local/bin/auto-update.sh
Paste the following into the file:
#!/bin/bash
# Update package lists and upgrade everything
apt-get update && apt-get dist-upgrade -y
# Clean up old files
apt-get autoremove -y
apt-get autoclean
# Log completion time
echo "Full system update completed on $(date)" >> /var/log/sys_update.log
Make the script executable:
sudo chmod +x /usr/local/bin/auto-update.sh
⏱️ Step 2: Schedule Monthly Updates with Cron
Open the root crontab:
sudo crontab -e
Add this line at the bottom:
0 3 1 * * /usr/local/bin/auto-update.sh
This runs the update script at 3:00 AM on the 1st day of every month.
🔁 Step 3 (Optional): Enable Auto‑Reboot
If you want the server to reboot after updates:
Open the script again:
sudo nano /usr/local/bin/auto-update.sh
Add this line at the very bottom:
/sbin/reboot
Save and exit.
✅ Step 4: Verify Everything
Check your scheduled cron jobs:
sudo crontab -l
Check the update log:
cat /var/log/sys_update.log
If you see timestamps, your automated updates are working correctly.
🎉 Done!
Your Ubuntu 24.04 VPN server will now stay updated, clean, and low‑maintenance with almost no effort.
Top comments (0)