What is a Cronjob?

Author: HOSTTEST Editorial   | 7 Jul 2018

cronjob.jpgA Cronjob is a recurring task in the server area that is automated to run at a specific time. This article explains what Cronjobs are, where the term comes from, and what they are used for.

To operate a server on the internet securely and reliably, it must be continuously administered and monitored. As part of this routine, not only individual security updates or software upgrades need to be worked on, but also various other tasks need to be performed, some of which must be done at regular intervals. This could include tasks such as creating backups or processing log files. To automate these tasks so that they do not have to be manually performed by the system administrator each time, they can be scheduled using so-called Cronjobs. Cronjobs can be set up on all Unix-based systems such as Linux/Unix or iOS/MacOS. The basis for this is the Cron Daemon, a system service that enables task automation. The term "Cron" is derived from the Greek word "chronos," which means "time." Additionally, the acronym Cron stands for "command run on notice."

How to set up Cronjobs?

In order to use Cronjobs, suitable web hosting is essential. Typically, setting up Cronjobs requires a Dedicated Server as the execution of a Cronjob requires system resources that would not be available to other customers on a Shared Web Hosting plan. However, some web hosts also offer Cronjob execution on regular web space packages. This is usually only available in higher-priced professional plans that allocate more system resources to the customer. Traditionally, a Cronjob is created directly through the server's command console via SSH (Secure Shell). It is also possible to upload Cron files to a web space package via an FTP server. The SSH process is as follows:

First, connect to your server via SSH. You will then have access to the command-line editor where you can enter further commands. Using the command crontab -e, you can create or edit a Cron file. The command crontab -l lists the contents of a Cron file. Cronjobs can also be deleted using the command crontab -r.

The Cron file itself consists of six columns arranged in a table format. The first five columns set the timestamp in the order of Minute, Hour, Day, Month, Weekday. The final column then contains the command to be executed. Each column is separated from the next by a space. By using the * symbol, you can designate a value as arbitrary.

A complete Cron command could look like this: 59 11 * * 1 /bin/test.sh

Here, /bin/test.sh will be executed every Monday at 11:59 am.

What are Cronjobs used for?

Cronjobs are used for regularly recurring tasks on a server that need to be automatically executed. These tasks may include:

  • Create Backups
  • Using a cron job, backups of databases or the entire system can be created automatically at predefined times. Especially for applications where content changes constantly, automated regular backups are helpful.
  • Create Logfiles
  • Cron jobs can be used to generate statistics on the page views of your own website. This way, the logfile can be updated automatically once a day.
  • Clean Databases
  • Over time, numerous unnecessary entries can accumulate in databases on a server. With the help of cron jobs, these can be cleaned up, such as automatically deleting old entries.
  • Send Emails
  • Especially in the area of newsletter distribution, cron jobs can help simplify work. Emails do not need to be manually sent to all recipients, but can be automatically dispatched.
  • Generate Invoices
  • Using cron jobs, invoices can also be created automatically, for example, when a specific task has been completed.
  • Run Updates
  • Most software applications deployed on servers need to be updated regularly. Cron jobs can also help here to automatically stay up to date.

The applications of cron jobs are diverse and can significantly ease the work of a system administrator. Therefore, anyone operating their own server should definitely delve into this topic.

Write a comment


More web hosts


More interesting articles