news
Serverspace has added a new Rocky Linux OS
JH
Joe Harris
February 27, 2021
Updated May 26, 2023

How to Set Up Cron Notifications to Email on Ubuntu 20.04

Linux Maintenance Ubuntu

Using another OS?

Select the desired version or distribution.

We have already covered setting up automatic scheduled tasks using cron in Ubuntu 20.04. In this tutorial we will look at an additional handy feature and set up sending Cron notifications to email.

Server preparation

First, you need to configure your server to be able to send emails. You can go through the steps in this tutorial - Postfix configuration as a Send-Only SMTP Server.

Following the instructions in the first two steps should be sufficient for our purposes. However, some mail servers will put unencrypted emails in the Spam folder or reject altogether.

Therefore, if you will not receive notifications as a result of following the steps in this guide, try checking your junk mail folder and enabling SMTP encryption (step 4 of the Postfix configuration guide).

To check the server's email logs, see:

cat /var/log/mail.log

Set up sending Cron notifications to email

Open the Cron configuration file.

crontab -e

Place this config in it. Replace the email address with yours.

MAILTO="mail@domain-name.com"
SHELL=/bin/bash
HOME=/
* * * * * echo "Message from Ubuntu cron"
Cron email notification
Screenshot 1. Cron email notification.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.