Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit 7e6d609

Browse files
author
Jag Talon
committed
Merge pull request #463 from nkorth/master
Added crontab cheat sheet goodie
2 parents 91929b7 + 2650090 commit 7e6d609

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package DDG::Goodie::CrontabCheatSheet;
2+
# ABSTRACT: Some examples of crontab syntax
3+
4+
# Adapted from VimCheatSheet.pm
5+
6+
use DDG::Goodie;
7+
8+
zci answer_type => "cron_cheat";
9+
10+
name "CrontabCheatSheet";
11+
description "Crontab cheat sheet";
12+
code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CrontabCheatSheet.pm";
13+
category "cheat_sheets";
14+
topics "computing", "geek", "programming", "sysadmin";
15+
16+
primary_example_queries 'crontab help', 'crontab cheat sheet', 'crontab example';
17+
18+
triggers startend => (
19+
'cron cheat sheet',
20+
'cron cheatsheet',
21+
'cron guide',
22+
'cron help',
23+
'cron quick reference',
24+
'cron reference',
25+
'cron example',
26+
'cron examples',
27+
'crontab cheat sheet',
28+
'crontab cheatsheet',
29+
'crontab guide',
30+
'crontab help',
31+
'crontab quick reference',
32+
'crontab reference',
33+
'crontab example',
34+
'crontab examples'
35+
);
36+
37+
attribution github => ["nkorth", "Nathan Korth"];
38+
39+
handle remainder => sub {
40+
return
41+
heading => 'Cron Cheat Sheet',
42+
html => html_cheat_sheet(),
43+
answer => text_cheat_sheet(),
44+
};
45+
46+
my $HTML;
47+
48+
sub html_cheat_sheet {
49+
$HTML //= share("crontab_cheat_sheet.html")
50+
->slurp(iomode => '<:encoding(UTF-8)');
51+
return $HTML;
52+
}
53+
54+
my $TEXT;
55+
56+
sub text_cheat_sheet {
57+
$TEXT //= share("crontab_cheat_sheet.txt")
58+
->slurp(iomode => '<:encoding(UTF-8)');
59+
return $TEXT;
60+
}
61+
62+
1;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<style type="text/css">
2+
.zci--answer .crontab-container {
3+
max-height: 23.3ex;
4+
overflow-y: auto;
5+
}
6+
.zci--answer .crontab-container .crontab-column {
7+
width: 48%;
8+
display: inline-block;
9+
vertical-align:top;
10+
}
11+
.zci--answer .crontab-container .crontab-column:first-child {
12+
margin-right: 3%;
13+
}
14+
.zci--answer .crontab-container p,
15+
.zci--answer .crontab-container .crontab-column {
16+
padding-top: 0;
17+
padding-bottom: 2ex;
18+
}
19+
.zci--answer .crontab-container table {
20+
width: 100%;
21+
}
22+
.zci--answer .crontab-container th {
23+
font-weight: bold;
24+
}
25+
.zci--answer .crontab-container td {
26+
vertical-align: top;
27+
}
28+
.zci--answer .crontab-container dd {
29+
margin-bottom: 1ex;
30+
}
31+
@media(max-width: 704px) {
32+
.zci--answer .crontab-container .crontab-column {
33+
width: 100%;
34+
margin-right: 0;
35+
display: block;
36+
}
37+
}
38+
</style>
39+
<div class="crontab-container">
40+
<div class="crontab-column">
41+
<p>Commands are executed by cron when the minute, hour, and month
42+
fields match the current time, and at least one of the two day fields
43+
(day of month, or day of week) match the current time. A field may be
44+
an asterisk (<code>*</code>), which will always match.</p>
45+
<table>
46+
<tr><th>Field</th><th>Allowed values</th>
47+
<tr><td>minute</td><td>0-59</td></tr>
48+
<tr><td>hour</td><td>0-23</td></tr>
49+
<tr><td>day of month</td><td>1-31</td></tr>
50+
<tr><td>month</td><td>1-12 or first three letters</td></tr>
51+
<tr><td>day of week</td><td>0-7 or first three letters<br>(0 or 7 is Sunday)</td></tr>
52+
</table>
53+
</div>
54+
<div class="crontab-column">
55+
<b>Examples</b>
56+
<dl>
57+
<dt>Run every Tuesday at 2:30</dt>
58+
<dd><code>30 2 * * tue /path/to/command</code></dd>
59+
<dt>Run every 10 minutes</dt>
60+
<dd><code>*/10 * * * * /path/to/command</code></dd>
61+
<dt>Run every 2 hours, on the half hour</dt>
62+
<dd><code>30 */2 * * * /path/to/command</code></dd>
63+
<dt>Run every 2 hours, on the half hour, but only on weekdays</dt>
64+
<dd><code>30 */2 * * 1-5 /path/to/command</code></dd>
65+
<dt>Run at 12:05, 13:05, ..., and 18:05</dt>
66+
<dd><code>5 12-18 * * * /path/to/command</code></dd>
67+
<dt>Run at 12:05, 14:05, 16:05, and 18:05</dt>
68+
<dd><code>5 12-18/2 * * * /path/to/command</code></dd>
69+
<dt>Run on the first day of every month, at midnight</dt>
70+
<dd><code>0 0 1 * * /path/to/command</code></dd>
71+
<dt>Run on the first day of every third month, at midnight</dt>
72+
<dd><code>0 0 1 */3 * /path/to/command</code></dd>
73+
</dl>
74+
</div>
75+
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Commands are executed by cron when the minute, hour, and month of year
2+
# fields match the current time, and at least one of the two day fields
3+
# (day of month, or day of week) match the current time. A field may be
4+
# an asterisk (*), which will always match.
5+
#
6+
# Fields in order:
7+
# minute (0-59)
8+
# hour (0-23)
9+
# day of month (1-31)
10+
# month (1-12 or first three letters)
11+
# day of week (0-7 or first three letters; 0 or 7 is Sunday)
12+
13+
# Run every Tuesday at 2:30am
14+
30 2 * * tue /path/to/command
15+
# or
16+
30 2 * * 2 /path/to/command
17+
18+
# Run every 10 minutes
19+
*/10 * * * * /path/to/command
20+
21+
# Run every 2 hours, on the half-hour
22+
30 */2 * * * /path/to/command
23+
24+
# Run every 2 hours on the half hour, but only on weekdays
25+
30 */2 * * 1-5 /path/to/command
26+
27+
# Run at 12:05, 13:05, ..., and 18:05
28+
5 12-18 * * * /path/to/command
29+
30+
# Run at 12:05, 14:05, 16:05, and 18:05
31+
5 12-18/2 * * * /path/to/command
32+
33+
# Run on the first day of every month, at 12:00am
34+
0 0 1 * * /path/to/command
35+
36+
# Run on the first day of every third month, at 12:00am
37+
0 0 1 */3 * /path/to/command

0 commit comments

Comments
 (0)