Cron Configuration Reference: Difference between revisions

From Sympl Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{Stub}}
{{Stub}}
Each domain in Sympl can have it's own [[crontab]] to run specific tasks. 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 tasks associated with domains.
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 Tasks ==
==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>.
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.
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>
<code>'''''minute hour day month day_of_week'''''  command_to_run</code>
Line 31: Line 31:
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.
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 ===
===Time Shortcuts===
There are a number of shortcuts for common times for tasks to run, which replaces the five values above.
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>
<code>'''''@shortcut'''''  command_to_run</code>
{| class="wikitable"
{| class="wikitable"
!Shortcut
!Shortcut
!Tasks will Run
!Jobs Will Run
|-
|-
|<code>@hourly</code>
|<code>@hourly</code>
|Every hour on the hour.
|Every hour on the hour.
|-
|-
|<code>@daily</code> or <code>@midnight</code>  
|<code>@daily</code> or <code>@midnight</code>
|Every day at midnight.
|Every day at midnight.
|-
|-
Line 56: Line 56:
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.
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 ===
===Example Configuration===
  # Send any output to webmaster@example.com
  # Send any output to webmaster@example.com
  MAILTO=webmaster@example.com
  MAILTO=webmaster@example.com
Line 71: Line 71:
  # Write the text "Happy New Year!" every year.
  # Write the text "Happy New Year!" every year.
  @yearly echo "Happy New 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 />
<br />
== Testing Configuration ==
Sympl includes a parser which allows you to check the next run-time of the tasks. Run <code>sympl-crontab --test /srv/'''''example.com'''''/config/crontab</code> to get a list of the configured tasks, and their next run-time.
==Configuration Reference==
==Configuration Reference==
<section begin=config />
<section begin=config />
{| class="wikitable sortable"
{| 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.
|[[Cron Configuration Reference|<small>More...</small>]]
|}
<section end=config /><blockquote>See also [https://wiki.sympl.host/view/Configuration_Reference ''Configuration Reference''] for other configuration files.</blockquote>

Revision as of 11:52, 19 July 2019

This article is a Stub. You can help the Sympl Project by expanding it.

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.