Generic

ID #1196

What is the syntax of a crontab line?

A crontab line looks like this:

<?php
* * * * * command to be executed

- - - - -

| | | | |

| | | | +-----
day of week (1 - 7) (monday = 1)

| | | +-------
month (1 - 12)

| | +---------
day of month (1 - 31)

| +-----------
hour (0 - 23)

+-------------
min (0 - 59)


?>


An asterix at a location means a wildcard, so valid for all possible values. A value may contain a comma separated list (see example below). The five fields are separated by spaces. Cron is very picky about the syntax, so when something doesn't work, check your entries.

So an example could be:

<?php
0 0
* * * rc_httpd restart

?>

This will restart your web servers at midnight.

The next line:

<?php
*/5 * * * * /path/to/do_something.sh

?>

starts a shell script called do_something every 5 minutes.

This line

<?php
* * * * * /bin/date &gt; /tmp/lastcron.txt
?>


will write the time and date to a log file every minute (the shortest cron interval) so you can verify crond is in fact running by looking at the timestamp in this file.

Finally here is an example of a comma separated value entry:

<?php
0 0
* * 1,3,5,7 /path/to/backup_script
?>


This line will execute a backup script @ midnight every other day, starting on Monday.

If you have a sendmail compatible mail server like exim installed on your FREESCO, then the root account will receive e-mails with the output of every cron entry that is executed. To avoid useless e-mails, you can redirect output- and error data to the /dev/null device, like so:

<?php
0 0
* * * /path/to/possibe_error &gt;/dev/null 2&gt;/dev/null
?>


Last update: 2005-05-04 10:18
Author: dingetje
Revision: 1.0

Print this record Print this record
Send to a friend Send to a friend
Show this as PDF file Show this as PDF file
Export as XML-File Export as XML-File

Please rate this entry:

Average rating: 5 from 5 (1 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry