Ubuntu Crontab

In this tutorial, we will show you, how to use the Ubuntu crontab. In a few simple steps, we will explain, how to automate your system tasks on Ubuntu, using the crontab in Ubuntu. The cron software utility is a time-based job scheduler in Unix-like operating systems. Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system-wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.

You can use cron on Ubuntu to automatically run scripts within a specified period of time, create a backup of your databases or other important files, monitor the services running on your server and many other things. Follow the steps below to set up the Ubuntu crontab.

1. Connect to your server and update your system

Before we begin with setting up crontab on your Ubuntu server, let’s connect to your VPS via SSH and update your system software to the latest available version.

We can do this by executing the following command:

apt-get update && apt-get upgrade

2. Check if the cron package is installed

To use the cron utility, we need to make sure that the cron package is installed on your server.

To check if cron is installed, we can run the following command:

dpkg -l cron

3. Install the cron package on Ubuntu

If the cron package is not installed on your server then you can install it with the package manager:

apt-get install cron

4.Verify if the cron service is running

To check whether the cron service is running on your system, we can use the following command:

systemctl status cron

5. Configure cron jobs on Ubuntu

In order to set up cron jobs, you need to modify the /etc/crontab file. Please note that this file can only be modified by the root user.
You can edit the crontab file with your favorite text editor, for example:

This will schedule the cron job to be executed at the beginning of each hour/day/week/month or upon server reboot.

If the scripts generate any kind of output, including errors, we can set up the cron job to log this output into a separate file. For example, the following cron will be executed three times a day at 4 AM, 10 AM and 16 PM every Wednesday and Saturday and any output (standard and error) will be logged into the backup.log file :

Of course, you don’t have to use Ubuntu crontab if you use one of our fully-managed Ubuntu hosting, in which case you can simply ask our expert Linux admins to help you with crontab on Ubuntu to automate system tasks. They are available 24×7 and will schedule any system tasks using crontab on your Ubuntu server, immediately!

PS. If you liked this post on Ubuntu crontab and how to automate system tasks, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks