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

For help in deciphering cron entries try Cron Text.

Q

What does the asterix mean in the cron job definition?

 

A

The asterix means "every." So "*" in the first position would mean "every minute," in the second postition "every hour," in the third "every day," etc.

Q

Can I schedule cron to run on weekdays only?

 

A

Yes.
As an example:
0 15 * * 1-5 /home/cronexample/insertownpath
This runs your cron every Monday through Friday at 3:00 PM.

Q

How do you set up cron on your operating system?

 

A

For Linux systems you use the cron application.

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 format does a crontab file need to follow?

 

A

A crontab is simply a list of cron jobs. Here is a link for a simple Crontab File Generator.
It is recommended by some that you leave a carriage return after the last job listed in the text document. For more info about cron jobs see What is a 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
Q

Are there alternatives to cron?

 

A

For Windows you would use the task manager. Psuedo cron works based on consistent levels of traffic to your website. See link below for more information:
www.bitfolde.de/?1=en&s=pseudocron

Valid XHTML 1.0 Transitional