You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

478 lines
16 KiB

{% extends "front/base_docs.html" %}
{% load hc_extras %}
{% block title %}Cron Syntax Cheatsheet - {% site_name %}{% endblock %}
{% block description %}
<meta name="description" content="Visual examples of main Cron syntax features: numeric values, commas, ranges, ranges with step, day and month names.">
{% endblock %}
{% block keywords %}
<meta name="keywords" content="cron syntax, crontab syntax, cron howto, cron tutorial, cron jobs, cron job example, monitor cron jobs">
{% endblock %}
{% block docs_content %}
<h2>Cron Syntax Cheatsheet</h2>
<p>
{% site_name %} understands most of the traditional cron syntax features.
Under the hood, it uses the
<a href="https://github.com/taichino/croniter">croniter package</a>
to parse and interpret cron expressions. Below is a showcase of
supported syntax features.
</p>
<p>
<strong>Pro-tip!</strong>
On Unix-like operating systems, you can also easily access cron syntax
documentation by typing <code>man 5 crontab</code> in shell.
</p>
<br />
<div id="cron-examples">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Basics</h3>
</div>
<div class="panel-body">
<p>A cron expression has five fields, separated by spaces.
Asterisk is a wild card character and means "any value".
</p>
<div class="desc">"Run every minute"</div>
<table class="cron-example">
<tr>
<th><div>* <span></span></div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td>Day of week, 0 - 7, 0 or 7 is Sun</td>
</tr>
<tr>
<td colspan="2">
Month, 1 - 12
</td>
</tr>
<tr>
<td colspan="3">
Day of month, 1 - 31
</td>
</tr>
<tr>
<td colspan="4">
Hour of day, 0 - 23
</td>
</tr>
<tr>
<td colspan="5">
Minute, 0 - 59
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Numeric values</h3>
</div>
<div class="panel-body">
<p>Use numeric values instead of asterisks to match specific
minutes, hours, days and months.
</p>
<div class="desc">"Run at 6PM on Fridays"</div>
<table class="cron-example">
<tr>
<th><div>0 <span></span></div></th>
<th><div>18</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>5</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td>Run only on Fridays</td>
</tr>
<tr>
<td colspan="2" class="minor">
Run every month of the year
</td>
</tr>
<tr>
<td colspan="3" class="minor">
Run every day of the month
</td>
</tr>
<tr>
<td colspan="4">
Run at 6PM
</td>
</tr>
<tr>
<td colspan="5">
Run at the start of the hour
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Commas</h3>
</div>
<div class="panel-body">
<p>Use <code>{v1},{v2},...,{vn}</code> to list multiple values.</p>
<div class="desc">"Run at 9AM, 12PM and 6PM every day"</div>
<table class="cron-example">
<tr>
<th><div>0 <span></span></div></th>
<th><div>9,12,18</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td class="minor">Run on every weekday</td>
</tr>
<tr>
<td colspan="2" class="minor">
Run every month of the year
</td>
</tr>
<tr>
<td colspan="3" class="minor">
Run every day of the month
</td>
</tr>
<tr>
<td colspan="4">
Run at 9AM, 12PM and 6PM
</td>
</tr>
<tr>
<td colspan="5">
Run at the start of the hour
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Ranges of values</h3>
</div>
<div class="panel-body">
<p>Use <code>{start}-{end}</code> to define a range of matching values.</p>
<div class="desc">"Run every minute on workdays"</div>
<table class="cron-example">
<tr>
<th><div>* <span></span></div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>1-5</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td>Run on Monday to Friday</td>
</tr>
<tr>
<td colspan="2" class="minor">
Run every month of the year
</td>
</tr>
<tr>
<td colspan="3" class="minor">
Run every day of the month
</td>
</tr>
<tr>
<td colspan="4" class="minor">
Run every hour of the day
</td>
</tr>
<tr>
<td colspan="5" class="minor">
Run every minute of the hour
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Ranges with a step</h3>
</div>
<div class="panel-body">
<p>Use <code>{start}-{end}/{step}</code> or <code>*/{step}</code>
to define a range with a step.</p>
<div class="desc">"Run every quarter of an hour"</div>
<table class="cron-example">
<tr>
<th><div>*/15 <span></span></div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td class="minor">Run on every weekday</td>
</tr>
<tr>
<td colspan="2" class="minor">
Run every month of the year
</td>
</tr>
<tr>
<td colspan="3" class="minor">
Run every day of the month
</td>
</tr>
<tr>
<td colspan="4" class="minor">
Run every hour of the day
</td>
</tr>
<tr>
<td colspan="5">
Run every 15 minutes
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Combine numeric values and ranges in lists</h3>
</div>
<div class="panel-body">
<p>In the comma-separated lists you can combine not only
numeric values but also ranges.</p>
<div class="desc">"Run every round hour outside office hours"</div>
<table class="cron-example">
<tr>
<th><div>0 <span></span></div></th>
<th><div>18-23,0-8</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
<th><div>*</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td class="minor">Run on every weekday</td>
</tr>
<tr>
<td colspan="2" class="minor">
Run every month of the year
</td>
</tr>
<tr>
<td colspan="3" class="minor">
Run every day of the month
</td>
</tr>
<tr>
<td colspan="4">
Run at 6PM, 7PM, 8PM, ..., 7AM, 8AM
</td>
</tr>
<tr>
<td colspan="5">
Run at the start of the hour
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Abbreviated day and month names</h3>
</div>
<div class="panel-body">
<p><code>JAN-DEC</code> can be used in the month field
and
<code>MON-SUN</code> in the weekday field.
</p>
<div class="desc">"Run every round hour on April 1st"</div>
<table class="cron-example">
<tr>
<th><div>0 <span></span></div></th>
<th><div>*</div></th>
<th><div>1</div></th>
<th><div>APR</div></th>
<th><div>*</div></th>
</tr>
<tr>
<td rowspan="5">
<div class="guide"></div>
</td>
<td rowspan="4">
<div class="guide"></div>
</td>
<td rowspan="3">
<div class="guide"></div>
</td>
<td rowspan="2">
<div class="guide"></div>
</td>
<td>
<div class="guide"></div>
</td>
<td class="minor">Run on every weekday</td>
</tr>
<tr>
<td colspan="2">
Run in April
</td>
</tr>
<tr>
<td colspan="3">
Run on the first day of the month
</td>
</tr>
<tr>
<td colspan="4" class="minor">
Run every hour of the day
</td>
</tr>
<tr>
<td colspan="5">
Run at the start of the hour
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Timezones</h3>
</div>
<div class="panel-body">
<p>
Cron daemon uses server's <strong>local time</strong>.
If your server's timezone is other than UTC, make sure
to set a matching timezone for your check
on {% site_name %} as well.
</p>
<p>On Ubuntu systems you can check the server's timezone
with:</p>
<pre>cat /etc/timezone</pre>
</div>
</div>
</div> <!-- cron examples -->
{% endblock %}