crontab

CronFAQ.com

Questions Frequently Asked About Cron

Q

What is cron?

 

A

Cron is a daemon (system service) used to execute scheduled commands on a unix system.

FreeBSD Man Page for Cron

Q

How does cron work?

 

A

Cron uses a table of jobs (crontab) which contains information about how often each job should run and what command the job should execute. When the appropriate time arrives the job is executed.

Q

What is cron job?

 

A

A cron job is a task that will be carried out on a regular basis by the cron daemon.

The definition of a job in the cron table (crontab) has six parts. Here is an example of a single job definition:

0 3 * * * /usr/local/sbin/dumpdatabases

The first five parts are defining the schedule on which the job will be executed. The sixth and last part defines the location of the script to be executed.

Below we will break down the job and explain each part.

Part 1 - This represents the minute the job will be executed. Possible values include a number from 0 to 59.

Part 2 - This is a number between 0 and 23 which represents the hour the job will be executed.

Part 3 - This represents the day of the month the job will be executed. A number between 1 and 31 can be used here.

Part 4 - This represents the month the job will be executed. This field uses a number between 1 and 12.

Part 5 - This represents the day of the week the job will be executed. For Sunday use the number 0. For Monday the number 1. And so on.

Part 6 - This contains the full path of the script that will be executed. Our example above shows the path to a script that will make a backup of the database files.

crontab entry diagram
Q

What is crontab?

 

A

Crontab is an abbreviation for cron table. This table is represented by a text file. Each line in the file represents one cron job.

Q

What is cron used for?

 

A

Cron executes other programs and scripts on a scheduled basis. There are many possible uses for cron. Here are a few examples.

  • schedule a regular backup of your database
  • update an RSS feed
  • retrieve information from a web page on a regular basis
Valid XHTML 1.0 Transitional