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

 

What This Script Does

  • Updates and upgrades your server daily. No more procrastinating updates.
  • Truncates oversized logs. User logs over 5MB? Gone. System logs over 100MB? Gone. It even keeps the latest entries intact using sponge.
  • Cleans up journal logs. Only the last 10 days of logs are retained. Because who really needs logs from last year?
  • Sends you a clear update. You’ll get notified if your server needs a reboot or if anything interesting happened during the cleanup.

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

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 to the crontab for notifications:

MAILTO="[email protected]"

This ensures you get an email summary of the script’s execution, including whether a reboot is required.

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:

  • Send you a clean, simple status message from each server.
  • Alert you if a reboot is needed.
  • Keep your logs in check, your updates fresh, and your disk space available.

No more waking up to find your server crying for help because of bloated logs or unpatched vulnerabilities.

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 enjoy the peace of mind knowing your Enhance servers are secure and tidy every single day.

Happy automating!

No comment

Leave a Reply

Your email address will not be published. Required fields are marked *