Facebook Pixel

Cron jobs: automatic execution of tasks on a web server. Your guide.

Cron jobs: automatic execution of tasks on a web server. Your guide.
If you don't know about it, there is a tool on web servers called "cron job" which allows tasks to be executed automatically. Indeed, thanks to this feature, you can automate a set of processes on a website or a server. In this article, we are going to see what it is, how it works, and its advantages. We will also give you some recommendations for better use. We recently developed an extension that synchronizes data using this feature.

To whom is this article addressed

Using a cron Job generally requires some basic knowledge of managing a web server. And also, you must have programming knowledge to know how to configure better. It is important to note that its use without in-depth knowledge can have consequences. For example, if you use this function to create a deleted post, a bad configuration or scheduler can cause:
  • deletion of important data;
  • unwanted addition of content;
  • the overload of your memory;
  • security vulnerabilities.
Our article is aimed at developers who want to better understand how to automate tasks. It also applies to business owners who intend to understand how it works.

What is a cron job?

A Cron Job is a job scheduling tool for Unix/Linux systems. Indeed, it allows you to program the execution of scripts or commands at specific times or at regular intervals, automatically and repetitively. Thus, on a web server, you can use it to perform various tasks such as
  • the backup of the database,
  • the updating of software,
  • sending reports
  • or email alerts, etc.

How to create a Cron Job?

To create a Cron Job on a web server, you must follow these steps:
  1. Connect to the server via an SSH connection or remote access.
  2. Open the configuration file using the command "crontab -e".
  3. Add a new line to the file by specifying the command to be executed and the execution frequency.
  4. Save and close the file.
The Cron Job line syntax is as follows:

* * * * * /chemin/vers/commande
The five stars represent the five fields for the time scheduling of the job:
  • The first field specifies the minutes (from 0 to 59).
  • The second field specifies the hours (from 0 to 23).
  • The third field specifies the days of the month (from 1 to 31).
  • The fourth field specifies the months (from 1 to 12).
  • The fifth field specifies the days of the week (from 0 to 6, where 0 represents Sunday).
Thus, to execute a daily command at 2 am, the Cron Job line would be:

0 2 * * * /chemin/vers/commande


A Cron job can be very useful in managing a website. Indeed, in managing the daily tasks of a website, it is particularly useful to reduce numerous manual activities. However, it is essential to make sure that the codes have no errors (if you execute a code). In addition, you must master the configuration to avoid inconvenience.

We use cookies to ensure that we give you the best experience on our website. By continuing to use this site, you consent to our use of cookies.

Our policy