Loading...
 

Crontab


Table of contents



Commands are executed by cron when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) matches the current time. Cron examines cron entries once every minute.

Syntax

*     *     *     *     *  command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)


Fields

A field may be an asterisk (*), which always stands for "first-last". Meaning that every possible value for that field will be used when it is examined by cron.

Individual numeric values are allowed

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an "hours" entry specifies execution at hours 8, 9, 10 and 11.

Lists of numbers are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: "1,2,5,9", "0-4,8-12"

Step values can be used in conjunction with ranges. Following a range with "/<number>" specifies skips of the number's value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour. Steps are also permitted after an asterisk, so if you want to say ``every two hours, just use ``*/2.

Examples

This command will execute at the top of the hour every hour of every day, of every month
0 * * * * /somecommand

This command will execute at the half hour every hour, monday through friday, of every month
30 * * * 1-5 /somecommand

This command will execute at the top of the hour every 4 hours, monday through friday, of every month
0 */3 * * 1-5 /somecommand

To execute a cron job every other week you can schedule you job to run every week and add this logic to the job so that it only really executes on odd or even weeks which will accomplish execution every other week. Just change your test to $ODD or $EVEN depending on which week you want to start executing the job on.
#!/bin/bash

# - Get the week number from "date"
WEEK=$(date +%W)
RESULT=$(expr $WEEK % 2)
EVEN=0
ODD=1

if [ $RESULT -eq $ODD ]; then
    echo "This is an odd week"
fi

Show php error messages