Cron Configuration Reference: Difference between revisions
(Created page with "{{Stub}} ==Configuration Reference== <section begin=config /> {| class="wikitable sortable" |+ !File or Directory !Used For !More |}<section end=config /><blockquote>See also...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{ | Each domain in Sympl can have it's own [[crontab]] to run specific jobs. This is configured the same as the normal system crontab, and is kept in <code>/srv/'''''example.com'''''/config/crontab</code> in order to keep jobs associated with domains. | ||
==Scheduling Jobs== | |||
The Sympl crontab works similarly to the normal system crontab, however the only environment variables which can be set are <code>PATH</code> and <code>MAILTO</code>. | |||
Each line starts with five values which specify when the job should be run, followed by the command to run, separated by whitespace. Comments begin with a hash (<code>#</code>) and must be on a line by themselves. Hours are specified on the 24 hour clock. | |||
<code>'''''minute hour day month day_of_week''''' command_to_run</code> | |||
{| class="wikitable" | |||
!Field | |||
!Allowed values | |||
|- | |||
|<code>'''''minute'''''</code> | |||
|<code>*</code> <code>0</code>-<code>59</code> <code>,</code> <code>-</code> <code>/</code> | |||
|- | |||
|<code>'''''hour'''''</code> | |||
|<code>*</code> <code>0</code>-<code>23</code> <code>,</code> <code>-</code> <code>/</code> | |||
|- | |||
|<code>'''''day'''''</code> | |||
|<code>*</code> <code>1</code>-<code>31</code> <code>,</code> <code>-</code> | |||
|- | |||
|<code>'''''month'''''</code> | |||
|<code>*</code> <code>1</code>-<code>12</code> or <code>JAN</code>-<code>DEC</code> <code>,</code> <code>-</code> | |||
|- | |||
|<code>'''''day_of_week'''''</code> | |||
|<code>*</code> <code>0</code>-<code>6</code> or <code>SUN</code>-<code>SAT</code> <code>,</code> <code>-</code> | |||
|} | |||
Commas (<code>,</code>) are used to separate items in lists, and hyphens (<code>-</code>) are ranges. | |||
The slash (<code>/</code>) is preceded by an asterisk (<code>*</code>) and followed by a number which indicates the job should run if the minute or hour is divisible by the number, for example a <code>'''''minuite'''''</code> value of <code>*/5</code> will run the task every <code>5</code> minutes. | |||
===Time Shortcuts=== | |||
There are a number of shortcuts for common times for jobs to run, which replaces the five values above. | |||
<code>'''''@shortcut''''' command_to_run</code> | |||
{| class="wikitable" | |||
!Shortcut | |||
!Jobs Will Run | |||
|- | |||
|<code>@hourly</code> | |||
|Every hour on the hour. | |||
|- | |||
|<code>@daily</code> or <code>@midnight</code> | |||
|Every day at midnight. | |||
|- | |||
|<code>@weekly</code> | |||
|Once a week on Sunday. | |||
|- | |||
|<code>@monthly</code> | |||
|Each month on the 1st at midnight. | |||
|- | |||
|<code>@yearly</code> or <code>@annually</code> | |||
|Midnight at Jan 1st each year | |||
|} | |||
Note that there is no <code>@reboot</code> entry supported. If you need a task to run after a reboot, you will need to add it in a system crontab. | |||
===Example Configuration=== | |||
# Send any output to webmaster@example.com | |||
MAILTO=webmaster@example.com | |||
# Run /srv/example.com/synchronise_orders.sh every 10 minutes. | |||
*/10 * * * * /srv/example.com/synchronise_orders.sh | |||
# Run /srv/example.com/mail_overnight_orders.sh at 9:00 on a Monday to Friday. | |||
0 9 * * MON-FRI /srv/example.com/mail_overnight_orders.sh | |||
# Run /srv/example.com/generate_stats.sh every day at midnight. | |||
@daily /srv/example.com/generate_stats.sh | |||
# Write the text "Happy New Year!" every year. | |||
@yearly echo "Happy New Year!" | |||
==Testing Configuration== | |||
Sympl includes a parser which allows you to check the next run-time of the jobs. Run <code>sympl-crontab --test /srv/'''''example.com'''''/config/crontab</code> to get a list of the configured jobs, and their next run-time. | |||
The above example, run on a Friday, looks like this: | |||
Environment | |||
------------------------------------------------------------------------------- | |||
HOME = /home/sympl | |||
LOGNAME = sympl | |||
PATH = /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games | |||
MAILTO = webmaster@example.com | |||
=============================================================================== | |||
Jobs next due -- Local time 2019-07-19 11:46:12 | |||
------------------------------------------------------------------------------- | |||
Next Run Time Command | |||
------------------------------------------------------------------------------- | |||
2019-07-19 11:50 /srv/example.com/synchronise_orders.sh | |||
2019-07-22 09:00 /srv/example.com/mail_overnight_orders.sh | |||
2019-07-20 00:00 /srv/example.com/generate_stats.sh | |||
2020-01-01 00:00 echo "Happy New Year!" | |||
=============================================================================== | |||
<br /> | |||
==Configuration Reference== | ==Configuration Reference== | ||
<section begin=config /> | <section begin=config /> | ||
{| class="wikitable | {| class="wikitable" | ||
!File or Directory | !File or Directory | ||
!Used For | !Used For | ||
!More | !More | ||
|}<section end=config /><blockquote>See also [https://wiki.sympl.host/view/Configuration_Reference ''Configuration Reference''] for other configuration files.</blockquote> | |- | ||
|<code>/srv/'''''example.com'''''/config/crontab</code> | |||
|Runs scheduled jobs as the <code>sympl</code> user, on a per-domain basis. | |||
|<small>[[Cron Configuration Reference#Scheduling Jobs|More...]]</small> | |||
|} | |||
<section end=config /><blockquote>See also [https://wiki.sympl.host/view/Configuration_Reference ''Configuration Reference''] for other configuration files.</blockquote> | |||
[[Category:Reference]] | |||
[[Category:Cron]] |
Latest revision as of 13:11, 19 July 2019
Each domain in Sympl can have it's own crontab to run specific jobs. This is configured the same as the normal system crontab, and is kept in /srv/example.com/config/crontab
in order to keep jobs associated with domains.
Scheduling Jobs
The Sympl crontab works similarly to the normal system crontab, however the only environment variables which can be set are PATH
and MAILTO
.
Each line starts with five values which specify when the job should be run, followed by the command to run, separated by whitespace. Comments begin with a hash (#
) and must be on a line by themselves. Hours are specified on the 24 hour clock.
minute hour day month day_of_week command_to_run
Field | Allowed values |
---|---|
minute
|
* 0 -59 , - /
|
hour
|
* 0 -23 , - /
|
day
|
* 1 -31 , -
|
month
|
* 1 -12 or JAN -DEC , -
|
day_of_week
|
* 0 -6 or SUN -SAT , -
|
Commas (,
) are used to separate items in lists, and hyphens (-
) are ranges.
The slash (/
) is preceded by an asterisk (*
) and followed by a number which indicates the job should run if the minute or hour is divisible by the number, for example a minuite
value of */5
will run the task every 5
minutes.
Time Shortcuts
There are a number of shortcuts for common times for jobs to run, which replaces the five values above.
@shortcut command_to_run
Shortcut | Jobs Will Run |
---|---|
@hourly
|
Every hour on the hour. |
@daily or @midnight
|
Every day at midnight. |
@weekly
|
Once a week on Sunday. |
@monthly
|
Each month on the 1st at midnight. |
@yearly or @annually
|
Midnight at Jan 1st each year |
Note that there is no @reboot
entry supported. If you need a task to run after a reboot, you will need to add it in a system crontab.
Example Configuration
# Send any output to webmaster@example.com MAILTO=webmaster@example.com # Run /srv/example.com/synchronise_orders.sh every 10 minutes. */10 * * * * /srv/example.com/synchronise_orders.sh # Run /srv/example.com/mail_overnight_orders.sh at 9:00 on a Monday to Friday. 0 9 * * MON-FRI /srv/example.com/mail_overnight_orders.sh # Run /srv/example.com/generate_stats.sh every day at midnight. @daily /srv/example.com/generate_stats.sh # Write the text "Happy New Year!" every year. @yearly echo "Happy New Year!"
Testing Configuration
Sympl includes a parser which allows you to check the next run-time of the jobs. Run sympl-crontab --test /srv/example.com/config/crontab
to get a list of the configured jobs, and their next run-time.
The above example, run on a Friday, looks like this:
Environment ------------------------------------------------------------------------------- HOME = /home/sympl LOGNAME = sympl PATH = /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games MAILTO = webmaster@example.com =============================================================================== Jobs next due -- Local time 2019-07-19 11:46:12 ------------------------------------------------------------------------------- Next Run Time Command ------------------------------------------------------------------------------- 2019-07-19 11:50 /srv/example.com/synchronise_orders.sh 2019-07-22 09:00 /srv/example.com/mail_overnight_orders.sh 2019-07-20 00:00 /srv/example.com/generate_stats.sh 2020-01-01 00:00 echo "Happy New Year!" ===============================================================================
Configuration Reference
File or Directory | Used For | More |
---|---|---|
/srv/example.com/config/crontab
|
Runs scheduled jobs as the sympl user, on a per-domain basis.
|
More... |
See also Configuration Reference for other configuration files.