Automating Updates and Log Maintenance on Your Enhance Server

Keeping your Linux server updated is crucial for maintaining security and performance. But let’s be honest – sometimes, server management feels like babysitting unruly toddlers. Whether it’s a rogue PHP script filling your error logs to the brim or some obscure process turning your logs into a hard drive hog, it’s all too easy to find your Enhance server gasping for disk space.
We’ve even seen Enhance servers run out of space overnight thanks to “stupid logs” ballooning out of control. Not fun.
So, to keep your server secure, tidy, and running smoothly, here’s a handy script we’ve cooked up. It handles daily updates, cleans out bloated logs, and keeps everything under control.
👉 Find the script here:
https://gist.github.com/cPFence/6b667f2404479a75cd9614973ea28c5f
Before scheduling: Read the current script first and keep a recoverable server backup. On Enhance with Ubuntu 22.04 or 24.04, check your package policy, paths and retention needs before using it. It runs full-upgrade and autoremove non-interactively, which can remove packages or interrupt services. Older log contents are permanently discarded, so preserve anything you need for an incident or support case.
What This Script Does
- Updates and upgrades your server daily. No more procrastinating updates.
- Truncates oversized logs. Matching user logs over 5MB are trimmed to their last 5MB; matching system and LiteSpeed logs over 100MB keep their last 100MB using
sponge. The current script preserves ownership and skipscpf_logsunder/var/www. - Cleans up journal logs. Its 10-day vacuum removes older archived journals; active journal files are unaffected. Increase the retention period if your troubleshooting needs it. See journalctl’s vacuum options.
- Prints a short update. It reports the reboot-required marker and clears the APT cache. Cron can email that output when mail delivery is configured.
How to Use It
Step 1: Save the Script
Copy the script from the link above and save it on your server, for example:
nano /root/daily_maintenance.sh
Make it executable:
chmod +x /root/daily_maintenance.sh
Step 2: Install sponge (if not already installed)
The script relies on sponge to keep only the latest entries in logs. Install it using:
apt-get install -y moreutils
Step 3: Set Up a Daily Cron Job
As root, add the script to your crontab for daily execution:
crontab -e
Add this line to run the script every day at 4:00 AM (or a time you’re awake, just in case an update goes sideways):
0 4 * * * /root/daily_maintenance.sh
Tip: Add your email above the job line in the crontab for notifications:
MAILTO="[email protected]"
With a working local mail transport, MAILTO sends cron output to that address. Confirm delivery rather than assuming the setting alone sends mail. The script’s “No reboot required” or “Script executed successfully” text does not prove every update succeeded: package output is suppressed and the final check does not track every earlier failure. Check APT logs and service health after the first run.
Why Timing Matters
We recommend scheduling the cron job at a time when you’re awake. If a package update causes any hiccups, you’ll be able to address the issue immediately.
What to Expect
Once set up, this script will:
- Print a short status message from each server, which cron can email if delivery works.
- Alert you if a reboot is needed.
- Keep your logs in check, your updates fresh, and your disk space available.
Less chance of waking up to a server crying for help—but keep an eye on failures, disk usage and the logs you choose to retain. To pause this automation, comment out its line in crontab -e; that prevents future runs and does not undo updates or restore truncated logs.
Stay on Top of Your Servers with Ease
With this setup, you can automate the boring bits of server maintenance and spend more time on what really matters (like making your coffee). So, go ahead, try it out, and keep your Enhance servers tidier while you monitor the results. OS maintenance complements cPFence v4+; use cpfence --status on each installed server to check its protection and license, separately from this script’s output.
Happy automating!
Try cPFence Free for One Month
Pair planned server maintenance with cPFence v4+ protection for your Enhance servers.
Start free trial

