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

  1. {% extends "front/base_docs.html" %}
  2. {% load hc_extras %}
  3. {% block title %}Cron Syntax Cheatsheet - {% site_name %}{% endblock %}
  4. {% block description %}
  5. <meta name="description" content="Visual examples of main Cron syntax features: numeric values, commas, ranges, ranges with step, day and month names.">
  6. {% endblock %}
  7. {% block keywords %}
  8. <meta name="keywords" content="cron syntax, crontab syntax, cron howto, cron tutorial, cron jobs, cron job example, monitor cron jobs">
  9. {% endblock %}
  10. {% block docs_content %}
  11. <h2>Cron Syntax Cheatsheet</h2>
  12. <p>
  13. {% site_name %} understands most of the traditional cron syntax features.
  14. Under the hood, it uses the
  15. <a href="https://github.com/taichino/croniter">croniter package</a>
  16. to parse and interpret cron expressions. Below is a showcase of
  17. supported syntax features.
  18. </p>
  19. <p>
  20. <strong>Pro-tip!</strong>
  21. On Unix-like operating systems, you can also easily access cron syntax
  22. documentation by typing <code>man 5 crontab</code> in shell.
  23. </p>
  24. <br />
  25. <div id="cron-examples">
  26. <div class="panel panel-default">
  27. <div class="panel-heading">
  28. <h3 class="panel-title">Basics</h3>
  29. </div>
  30. <div class="panel-body">
  31. <p>A cron expression has five fields, separated by spaces.
  32. Asterisk is a wild card character and means "any value".
  33. </p>
  34. <div class="desc">"Run every minute"</div>
  35. <table class="cron-example">
  36. <tr>
  37. <th><div>* <span></span></div></th>
  38. <th><div>*</div></th>
  39. <th><div>*</div></th>
  40. <th><div>*</div></th>
  41. <th><div>*</div></th>
  42. </tr>
  43. <tr>
  44. <td rowspan="5">
  45. <div class="guide"></div>
  46. </td>
  47. <td rowspan="4">
  48. <div class="guide"></div>
  49. </td>
  50. <td rowspan="3">
  51. <div class="guide"></div>
  52. </td>
  53. <td rowspan="2">
  54. <div class="guide"></div>
  55. </td>
  56. <td>
  57. <div class="guide"></div>
  58. </td>
  59. <td>Day of week, 0 - 7, 0 or 7 is Sun</td>
  60. </tr>
  61. <tr>
  62. <td colspan="2">
  63. Month, 1 - 12
  64. </td>
  65. </tr>
  66. <tr>
  67. <td colspan="3">
  68. Day of month, 1 - 31
  69. </td>
  70. </tr>
  71. <tr>
  72. <td colspan="4">
  73. Hour of day, 0 - 23
  74. </td>
  75. </tr>
  76. <tr>
  77. <td colspan="5">
  78. Minute, 0 - 59
  79. </td>
  80. </tr>
  81. </table>
  82. </div>
  83. </div>
  84. <div class="panel panel-default">
  85. <div class="panel-heading">
  86. <h3 class="panel-title">Numeric values</h3>
  87. </div>
  88. <div class="panel-body">
  89. <p>Use numeric values instead of asterisks to match specific
  90. minutes, hours, days and months.
  91. </p>
  92. <div class="desc">"Run at 6PM on Fridays"</div>
  93. <table class="cron-example">
  94. <tr>
  95. <th><div>0 <span></span></div></th>
  96. <th><div>18</div></th>
  97. <th><div>*</div></th>
  98. <th><div>*</div></th>
  99. <th><div>5</div></th>
  100. </tr>
  101. <tr>
  102. <td rowspan="5">
  103. <div class="guide"></div>
  104. </td>
  105. <td rowspan="4">
  106. <div class="guide"></div>
  107. </td>
  108. <td rowspan="3">
  109. <div class="guide"></div>
  110. </td>
  111. <td rowspan="2">
  112. <div class="guide"></div>
  113. </td>
  114. <td>
  115. <div class="guide"></div>
  116. </td>
  117. <td>Run only on Fridays</td>
  118. </tr>
  119. <tr>
  120. <td colspan="2" class="minor">
  121. Run every month of the year
  122. </td>
  123. </tr>
  124. <tr>
  125. <td colspan="3" class="minor">
  126. Run every day of the month
  127. </td>
  128. </tr>
  129. <tr>
  130. <td colspan="4">
  131. Run at 6PM
  132. </td>
  133. </tr>
  134. <tr>
  135. <td colspan="5">
  136. Run at the start of the hour
  137. </td>
  138. </tr>
  139. </table>
  140. </div>
  141. </div>
  142. <div class="panel panel-default">
  143. <div class="panel-heading">
  144. <h3 class="panel-title">Commas</h3>
  145. </div>
  146. <div class="panel-body">
  147. <p>Use <code>{v1},{v2},...,{vn}</code> to list multiple values.</p>
  148. <div class="desc">"Run at 9AM, 12PM and 6PM every day"</div>
  149. <table class="cron-example">
  150. <tr>
  151. <th><div>0 <span></span></div></th>
  152. <th><div>9,12,18</div></th>
  153. <th><div>*</div></th>
  154. <th><div>*</div></th>
  155. <th><div>*</div></th>
  156. </tr>
  157. <tr>
  158. <td rowspan="5">
  159. <div class="guide"></div>
  160. </td>
  161. <td rowspan="4">
  162. <div class="guide"></div>
  163. </td>
  164. <td rowspan="3">
  165. <div class="guide"></div>
  166. </td>
  167. <td rowspan="2">
  168. <div class="guide"></div>
  169. </td>
  170. <td>
  171. <div class="guide"></div>
  172. </td>
  173. <td class="minor">Run on every weekday</td>
  174. </tr>
  175. <tr>
  176. <td colspan="2" class="minor">
  177. Run every month of the year
  178. </td>
  179. </tr>
  180. <tr>
  181. <td colspan="3" class="minor">
  182. Run every day of the month
  183. </td>
  184. </tr>
  185. <tr>
  186. <td colspan="4">
  187. Run at 9AM, 12PM and 6PM
  188. </td>
  189. </tr>
  190. <tr>
  191. <td colspan="5">
  192. Run at the start of the hour
  193. </td>
  194. </tr>
  195. </table>
  196. </div>
  197. </div>
  198. <div class="panel panel-default">
  199. <div class="panel-heading">
  200. <h3 class="panel-title">Ranges of values</h3>
  201. </div>
  202. <div class="panel-body">
  203. <p>Use <code>{start}-{end}</code> to define a range of matching values.</p>
  204. <div class="desc">"Run every minute on workdays"</div>
  205. <table class="cron-example">
  206. <tr>
  207. <th><div>* <span></span></div></th>
  208. <th><div>*</div></th>
  209. <th><div>*</div></th>
  210. <th><div>*</div></th>
  211. <th><div>1-5</div></th>
  212. </tr>
  213. <tr>
  214. <td rowspan="5">
  215. <div class="guide"></div>
  216. </td>
  217. <td rowspan="4">
  218. <div class="guide"></div>
  219. </td>
  220. <td rowspan="3">
  221. <div class="guide"></div>
  222. </td>
  223. <td rowspan="2">
  224. <div class="guide"></div>
  225. </td>
  226. <td>
  227. <div class="guide"></div>
  228. </td>
  229. <td>Run on Monday to Friday</td>
  230. </tr>
  231. <tr>
  232. <td colspan="2" class="minor">
  233. Run every month of the year
  234. </td>
  235. </tr>
  236. <tr>
  237. <td colspan="3" class="minor">
  238. Run every day of the month
  239. </td>
  240. </tr>
  241. <tr>
  242. <td colspan="4" class="minor">
  243. Run every hour of the day
  244. </td>
  245. </tr>
  246. <tr>
  247. <td colspan="5" class="minor">
  248. Run every minute of the hour
  249. </td>
  250. </tr>
  251. </table>
  252. </div>
  253. </div>
  254. <div class="panel panel-default">
  255. <div class="panel-heading">
  256. <h3 class="panel-title">Ranges with a step</h3>
  257. </div>
  258. <div class="panel-body">
  259. <p>Use <code>{start}-{end}/{step}</code> or <code>*/{step}</code>
  260. to define a range with a step.</p>
  261. <div class="desc">"Run every quarter of an hour"</div>
  262. <table class="cron-example">
  263. <tr>
  264. <th><div>*/15 <span></span></div></th>
  265. <th><div>*</div></th>
  266. <th><div>*</div></th>
  267. <th><div>*</div></th>
  268. <th><div>*</div></th>
  269. </tr>
  270. <tr>
  271. <td rowspan="5">
  272. <div class="guide"></div>
  273. </td>
  274. <td rowspan="4">
  275. <div class="guide"></div>
  276. </td>
  277. <td rowspan="3">
  278. <div class="guide"></div>
  279. </td>
  280. <td rowspan="2">
  281. <div class="guide"></div>
  282. </td>
  283. <td>
  284. <div class="guide"></div>
  285. </td>
  286. <td class="minor">Run on every weekday</td>
  287. </tr>
  288. <tr>
  289. <td colspan="2" class="minor">
  290. Run every month of the year
  291. </td>
  292. </tr>
  293. <tr>
  294. <td colspan="3" class="minor">
  295. Run every day of the month
  296. </td>
  297. </tr>
  298. <tr>
  299. <td colspan="4" class="minor">
  300. Run every hour of the day
  301. </td>
  302. </tr>
  303. <tr>
  304. <td colspan="5">
  305. Run every 15 minutes
  306. </td>
  307. </tr>
  308. </table>
  309. </div>
  310. </div>
  311. <div class="panel panel-default">
  312. <div class="panel-heading">
  313. <h3 class="panel-title">Combine numeric values and ranges in lists</h3>
  314. </div>
  315. <div class="panel-body">
  316. <p>In the comma-separated lists you can combine not only
  317. numeric values but also ranges.</p>
  318. <div class="desc">"Run every round hour outside office hours"</div>
  319. <table class="cron-example">
  320. <tr>
  321. <th><div>0 <span></span></div></th>
  322. <th><div>18-23,0-8</div></th>
  323. <th><div>*</div></th>
  324. <th><div>*</div></th>
  325. <th><div>*</div></th>
  326. </tr>
  327. <tr>
  328. <td rowspan="5">
  329. <div class="guide"></div>
  330. </td>
  331. <td rowspan="4">
  332. <div class="guide"></div>
  333. </td>
  334. <td rowspan="3">
  335. <div class="guide"></div>
  336. </td>
  337. <td rowspan="2">
  338. <div class="guide"></div>
  339. </td>
  340. <td>
  341. <div class="guide"></div>
  342. </td>
  343. <td class="minor">Run on every weekday</td>
  344. </tr>
  345. <tr>
  346. <td colspan="2" class="minor">
  347. Run every month of the year
  348. </td>
  349. </tr>
  350. <tr>
  351. <td colspan="3" class="minor">
  352. Run every day of the month
  353. </td>
  354. </tr>
  355. <tr>
  356. <td colspan="4">
  357. Run at 6PM, 7PM, 8PM, ..., 7AM, 8AM
  358. </td>
  359. </tr>
  360. <tr>
  361. <td colspan="5">
  362. Run at the start of the hour
  363. </td>
  364. </tr>
  365. </table>
  366. </div>
  367. </div>
  368. <div class="panel panel-default">
  369. <div class="panel-heading">
  370. <h3 class="panel-title">Abbreviated day and month names</h3>
  371. </div>
  372. <div class="panel-body">
  373. <p><code>JAN-DEC</code> can be used in the month field
  374. and
  375. <code>MON-SUN</code> in the weekday field.
  376. </p>
  377. <div class="desc">"Run every round hour on April 1st"</div>
  378. <table class="cron-example">
  379. <tr>
  380. <th><div>0 <span></span></div></th>
  381. <th><div>*</div></th>
  382. <th><div>1</div></th>
  383. <th><div>APR</div></th>
  384. <th><div>*</div></th>
  385. </tr>
  386. <tr>
  387. <td rowspan="5">
  388. <div class="guide"></div>
  389. </td>
  390. <td rowspan="4">
  391. <div class="guide"></div>
  392. </td>
  393. <td rowspan="3">
  394. <div class="guide"></div>
  395. </td>
  396. <td rowspan="2">
  397. <div class="guide"></div>
  398. </td>
  399. <td>
  400. <div class="guide"></div>
  401. </td>
  402. <td class="minor">Run on every weekday</td>
  403. </tr>
  404. <tr>
  405. <td colspan="2">
  406. Run in April
  407. </td>
  408. </tr>
  409. <tr>
  410. <td colspan="3">
  411. Run on the first day of the month
  412. </td>
  413. </tr>
  414. <tr>
  415. <td colspan="4" class="minor">
  416. Run every hour of the day
  417. </td>
  418. </tr>
  419. <tr>
  420. <td colspan="5">
  421. Run at the start of the hour
  422. </td>
  423. </tr>
  424. </table>
  425. </div>
  426. </div>
  427. <div class="panel panel-default">
  428. <div class="panel-heading">
  429. <h3 class="panel-title">Timezones</h3>
  430. </div>
  431. <div class="panel-body">
  432. <p>
  433. Cron daemon uses server's <strong>local time</strong>.
  434. If your server's timezone is other than UTC, make sure
  435. to set a matching timezone for your check
  436. on {% site_name %} as well.
  437. </p>
  438. <p>On Ubuntu systems you can check the server's timezone
  439. with:</p>
  440. <pre>cat /etc/timezone</pre>
  441. </div>
  442. </div>
  443. </div> <!-- cron examples -->
  444. {% endblock %}