What is a cron job?
Cron jobs are tasks that run automatically in Unix derivatives and BSD operating systems. For this purpose, the system issues certain commands at regular intervals. The advantage of cron jobs is that they can be highly individualized.
Cron jobs can be used on all operating systems that have a cron system or a cron daemon. These are Unix systems (macOS, Linux, etc.) or BSD systems (“Berkeley Software Distribution”).
Cron is an abbreviation for “Command run on notice”. At the same time, the expression is a play on words that is supposed to be reminiscent of Chronos, the ancient Greek deity of time. This expresses that, as part of a cron job, certain commands are executed by the operating system at previously defined time intervals. Routine tasks run automatically in this way.
Requirements for setting up cron jobs
In order to be able to set up cron jobs, the following requirements must be met:
- own server (dedicated server)
- SecureShell (SSH) or Telnet client (for access)
- FTP program (for uploading cron files or scripts)
- optional for cron jobs in connection with websites: cron job provider or web hosting package that includes cron jobs
- optional: program for setting up a graphical user interface (e.g. GNOME) so that you do not have to write any codes
Individualization: the great advantage of cron jobs
Cron jobs have three standard commands that always work:
- PATH: the way in which to search for commands or a script
- SHELL: indicates which interpreter of commands has to execute a script
- MAILTO: indicates with which users you want to share scripts or the results of the jobs
But these are not all possibilities. Users can also define any variables themselves. In this way, cron jobs offer a high degree of customization options. This is their great advantage because they are also able to automate tasks in very different contexts of use.
Examples of possible uses of cron jobs
Cron jobs are commonly used, for example, to create backups at regular intervals. The cleaning of databases is also not infrequently encountered as a correspondingly automated task. For web servers, the processing of visitor statistics often runs as a cron job.
In conjunction with a content management system, newsletters can be sent automatically or stock levels checked in this way. Cron jobs can also generate reports on server loads or recalculate certain information in online shops and display them accordingly – for example product reviews.
The use of such automated tasks, however, has a downside: Cron jobs require resources. This can be problematic, especially in conjunction with a website, as loading times for visitors can increase, for example. It therefore doesn’t always make sense to let too many of the jobs run, especially not at peak traffic times.