cron

cron

Cron is a time-based job scheduler in Unix-like operating systems. It allows users to schedule commands to run at specific times, dates, or intervals. Cron is often used to automate tasks such as backups, software updates, and email notifications.

Cron jobs are defined in crontab files. Each user has their own crontab file, which is located in the /var/spool/cron/crontabs directory. The crontab file contains a list of tasks that the cron daemon will execute.

Each task in the crontab file is defined by a cron expression. A cron expression is a string that specifies the time and date that the task should be executed.

The cron daemon reads the crontab files every minute and executes the tasks that are due to run. If a task fails to run, the cron daemon will try again the next minute.

Here is an example of a cron expression that would run the command /path/to/script.sh at 10:00 AM every day:

0 10 * * * /path/to/script.sh

The cron expression is broken down into five parts:

  • Minute: The minute of the hour. In this example, the task will run at 0 minutes past the hour (i.e., 10:00 AM).

  • Hour: The hour of the day. In this example, the task will run at 10 AM.

  • Day of the month: The day of the month. In this example, the task will run every day.

  • Month: The month of the year. In this example, the task will run every month.

  • Day of the week: The day of the week. In this example, the task will run every day of the week.

You can use any combination of these parts to create a cron expression that specifies the time and date that you want your task to run.

For more information on cron expressions, you can refer to the following resources:

  • The cron man page: https://linux.die.net/man/5/crontab

  • The crontab.guru website: https://crontab.guru/

  • The Cronitor website: https://cronitor.io/

help

Last updated