What is Cron?
Cron is a program that enables you to execute a command, or a script with a sequence of
commands, at a specified date, time or at set intervals. The commands or scripts that you want
cron to run are defined in a file called crontab, and every user has their own independent
crontab file. Cron is a system program that is running all the time and is similar to the
Windows scheduler which allows you to run commands/programs at predefined times and intervals.
This tutorial will explain how to use Cron and crontab and contains some basic working examples
that should hopefully illustrate how it functions.
Note: Cron is only available on the CGI server. It is not possible to run scheduled commands or
scripts on the homepages (www) server.
How do I use
Cron?
There is a special format for entering crontabs:
| Minute Hour Day Month Day Task |
| MAILTO=cron@username.domain.com |
| MAILTO=cron@username.plus.com * * * * * /command/to/execute |
| MAILTO=cron@username.plus.com 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /command/to/execute |
| MAILTO=cron@username.plus.com */5 * * * * /command/to/execute |
| MAILTO=cron@username.plus.com 00 18 * * * /command/to/execute |
| MAILTO=cron@username.plus.com 00 02 * * sun /usr/local/bin/php $HOME/php/script.php |
| tutorialsteam@shell2 tutorialsteam $ more Mailbox From root@shell1.cgi.plus.net Sun Feb 01 23:11:27 2004 Return-Path: <root@shell1.cgi.plus.net> Delivered-To: tutorialsteam@shell1.cgi.plus.net Received: (qmail 18527 invoked by uid 10667); 1 Feb 2004 23:11:25 -0000 Date: 1 Feb 2004 23:11:25 -0000 Message-ID: <20040201231125.18514.qmail@shell1.cgi.plus.net> From: root@shell1.cgi.plus.net (Cron Daemon) To: tutorialsteam@shell1.cgi.plus.net Subject: Cron <tutorialsteam@shell2> $HOME/me X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/files/home2/tutorialsteam> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=tutorialsteam> I am: uid=10667(tutorialsteam) gid=500(shellcgi) groups=500(shellcgi) PATH is set to: /usr/bin:/bin |
| $ crontab -l >mycrontab |