How-To: email notification upon available package updates with cron-apt

1 minute read

cron-apt is a tool run by a cron job at regular interval that will check for package updates and optionally do some actions.

cron-apt will by default download the packages without installing them.

This tutorial will explain how to set up cron-apt in order to have it send an email to a specified address when updates are ready to be installed.

One of the basic rule in order to have a system protected against software exploits is to keep its software up to date.

Recent Linux desktop distribution include update-notifier which visually show the availability of new update.

In non graphical mode, such as a server running 24/7, one need to manually log in and run:

# apt-get update
# apt-get dist-upgrade

This simple task can get cumbersome mainly if you administer a lot of system.

cron-apt will check for updates for you and alternatively install the updates or send an email to a specified address.

I would not recommend installing the updates automatically, as I prefer to be around to see what is going on and, in case something goes wrong, be able to interact.

On the other hand, email notification allows you to apply the updates in a timely fashion.

1. Installation

On both Ubuntu and Debian, cron-apt can be installed by typing:

# apt-get install cron-apt

2. Configuration

cron-tab configuration is pretty straightforward. A lot of feature are available but this article will limit its usage at sending email notifications.

The main configuration file is /etc/cron-apt/config. Open and edit this file and make sure the variable MAILTO is set to the email you want to receive the updates summary at, and MAILON is set to upgrade:

MAILTO="[email protected]"

Alternatively, you can change MAILON to always in order to receive the summary any time cron-apt is ran.

3. Defining when cron-apt has to run

As cron-apt is a cron job, you can define when to run it by editing /etc/cron.d/cron-apt.

The default configuration will run cron-apt every day at 4am.