Skip to content

Ubuntu Maintenance Automation: Update, Upgrade, Clean and Reboot

Managing a cloud server is not an easy task, there are specific maintenance tasks that need to be executed on a daily, weekly, and monthly basis. However, these cloud servers offer programs like CORN jobs that can help automate these maintenance tasks. We can set up upgrade, autoclean, and autoremove along with reboot the cloud server.

A primary job of the webmaster or server administrator is to keep the online server healthy, running, and up to date. While the Ubuntu maintenance task seems straightforward, technically, it’s become difficult with more hacking, data breach, and theft these days.

One of the primary reasons is the outdated software program. Hence, keeping the server updated with all the security patch releases and the latest version is essential.

In this article, we will learn different command lines that help maintain the Ubuntu cloud server. We will learn how to update, upgrade and clean up the old obsolete files. We are also going to automate these tasks using CRON jobs.

Also, if you’re following us, this is the twelfth article and video tutorial in the #CloudServer series. We earlier published about DigitalOcean Droplet Backups and Snapshot.

Let’s get started with Ubuntu maintenance and automation —

Ubuntu Maintenance Task using Command Line

A server administrator performs primary maintenance tasks by upgrading and cleaning up the old files. You can use the below commands via your SSH login to run and perform maintenance of the Ubuntu cloud server.

Update the apt repository using below CLI command:

sudo apt-get update

Upgrade the Ubuntu Server Distribution using the below command:

sudo apt-get dist-upgrade -y
Ubuntu Cloud Server Update and Upgrade

Upgrade the entire Ubuntu Server using the below command:

sudo apt-get upgrade -y

Remove the older Ubuntu upgraded system files using the below command

sudo apt-get autoremove

Clean the obsolete Ubuntu server files using the below command:

sudo apt-get autoclean
Ubuntu Maintenance and Clean up Commands

Reboot the Ubuntu cloud server using the below command:

reboot

There is no harm in running these commands multiple times in a day except rebooting. However, it’s recommended to perform upgrades and cleanups at least once weekly. Especially the security upgrades that keep the server healthy.

Automating Ubuntu Maintenance using CRONTAB

The command lines previously needed to be manually executed via SSH. This could be easily eliminated using CRON job automation.

We will set up a rule that will tell the Ubuntu cloud server when to execute a set of pre-defined commands. These commands basically update, upgrade and also clean and remove the old.

Ubuntu server files and replace them with the newest version.

Let’s get started with the automation —

Login into your Cloud Server SSH client and edit the crontab file using the below command:

sudo nano /etc/crontab

Insert the below Ubuntu maintenance after all other existing rules. It will execute the CRON job at the set daily interval at 0425 server time.

25 4 * * * root sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
Ubuntu maintenance automation using CRONTAB

We can translate the above CRON job rule as below:

m h dom mon dow user command
minute hour dayOfMonth Month dayOfWeek userToRun commandToRun

You can customize the Ubuntu maintenance automation per your needs and timings. I analyzed my Google Analytics audience report to understand the lowest traffic point and set up the CRON job to run the task at 0425 hours daily.

Once you’ve added the above rule to the crontab file, do not forget to reboot the cloud server using the below command:

reboot

Scheduling Weekly Server Reboot (Optional)

The Ubuntu cloud server is pretty powerful and does not require frequent reboots. However, it is a good idea to reboot the server once a week or at least whenever you notice the alert saying *** system reboot required *** after login into the SSH client.

You can even automate the periodical reboot using the CRON jobs. All you need is to add the following snippet in the crontab file for a weekly reboot on Sunday at 0525 hours server time.

25 5 * * 1 root sudo reboot

I reboot once in a while when I notice the alert mentioned above; however, as a system administrator, you can schedule the reboot automation using the above rule in a /etc/crontab file.

You can even customize the time and frequency per need. Also, I do not suggest rebooting the Ubuntu server daily unless required to maintain smooth functioning.

Watch Ubuntu Maintenance Tutorial

Watch the complete video tutorial about Ubuntu Cloud Server maintenance and its automation. It’s essential to keep your server up to date and healthy.

Ubuntu Cloud Server Maintenance Automation: update, upgrade, cleanup

I hope you liked the video; please subscribe to our YouTube channel for more videos.

What’s next in the #CloudServer Series?

We have learned how to maintain the Ubuntu Cloud Server in the long run. And also automating the essential maintenance task using the CRON jobs feature.

Next, we will touch base on the Ubuntu error logs and get support for resolving any issue with the Cloud Server.

Kushal Azza

Kushal Azza

Kushal Azza is a Google Certified IT Professional, Digital Content Creator, and Go-To Digital Marketer. He has over a decade of experience solving tech problems, troubleshooting, and creating digital solutions. Follow him on Twitter and LinkedIn.

Leave a Reply

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