(You must already be logged in to Gitlab or you’ll hit a 404)
Setting up a scheduled task
Each domain has the ability to run its own scheduled tasks via a file known as a
crontab. This file enables jobs to be run on at specific times on specific days.
The format is the same as the well-known
crontab file used on many
A domain’s crontab is found at
config/crontab. For example, the crontab for
my-brilliant-site.com would be found at
The crontab format
The file is a list of jobs, one per line. Each line specifies first the times and days at which a job should run, followed by the command to run.
The first five fields, which are separated by spaces, specify the time and date at which the job should run. The rest of the line is interpreted as the command.
|day of month||1-31|
|month||1-12 (or names, see below)|
|day of week||0-7 (0 or 7 is Sunday, or use names)|
In addition an asterisk can be used to indicate for every allowed value. For
example, to execute the command
echo Hello Dave. at 18:40 every day, the
crontab line would read as follows.
40 18 * * * echo Hello Dave.
Three-letter names can also be specified for use in instead of numbers for days of the week and months.
Sun, Mon, Tue, Wed, Thu, Fri, Sat
Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
Any output generated by a command will be sent to the root account, unless specified otherwise. If no output is generated, no email will be sent.
The fields can be specified in the following ways:
- As a comma separated list, e.g.
- As a range, e.g.
1-3would mean 1, 2, 3
- As a range with a step, e.g.
0-30/2, would mean 0, 2, 4, 6 and so on until 30.
- Or any combination of the above three, e.g.
1,2,10-12,20-24/2would mean 1, 2, 10, 11, 12, 20, 22, 24.
Ranges can also be specified across “boundaries”. For example
the hour field will be interpreted as
22, 23, 0, 1, 2;
Nov-Feb in the
month field will mean
11, 12, 1, 2.
There is also a selection of shortcuts available:
@hourly— every hour, on the hour,
@midnight— every day at midnight,
@weekly— every week at midnight on Sunday,
@monthly— every month, at midnight on the first day of the month,
@annually— every year, at midnight on 1st January.
The full crontab format is explained in more detail in the crontab (5) manual page.
@rebootshortcut is not supported.
Mailing the output
The output can be emailed to any recipient by specifying the MAILTO parameter at the top of the file.
For example, we would like to mail any output from our commands to firstname.lastname@example.org.
# # send any output to Bob # MAILTOemail@example.com # # run at 9am every Monday - Friday # 0 9 * * 1-5 wget http://www.my-brilliant-site.com/cron.php
MAILTO is not set, or no recipient is specified, then they output
will be sent to the domain directory’s owner, e.g. if
/srv/my-brilliant-site.com/ were owned by
admin, the output would
get sent to firstname.lastname@example.org.