Merge pull request #463 from nkorth/master

Added crontab cheat sheet goodie
master
Jag Talon 2014-07-01 14:35:58 -04:00
commit 7e6d609ad4
3 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package DDG::Goodie::CrontabCheatSheet;
# ABSTRACT: Some examples of crontab syntax
# Adapted from VimCheatSheet.pm
use DDG::Goodie;
zci answer_type => "cron_cheat";
name "CrontabCheatSheet";
description "Crontab cheat sheet";
code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/CrontabCheatSheet.pm";
category "cheat_sheets";
topics "computing", "geek", "programming", "sysadmin";
primary_example_queries 'crontab help', 'crontab cheat sheet', 'crontab example';
triggers startend => (
'cron cheat sheet',
'cron cheatsheet',
'cron guide',
'cron help',
'cron quick reference',
'cron reference',
'cron example',
'cron examples',
'crontab cheat sheet',
'crontab cheatsheet',
'crontab guide',
'crontab help',
'crontab quick reference',
'crontab reference',
'crontab example',
'crontab examples'
);
attribution github => ["nkorth", "Nathan Korth"];
handle remainder => sub {
return
heading => 'Cron Cheat Sheet',
html => html_cheat_sheet(),
answer => text_cheat_sheet(),
};
my $HTML;
sub html_cheat_sheet {
$HTML //= share("crontab_cheat_sheet.html")
->slurp(iomode => '<:encoding(UTF-8)');
return $HTML;
}
my $TEXT;
sub text_cheat_sheet {
$TEXT //= share("crontab_cheat_sheet.txt")
->slurp(iomode => '<:encoding(UTF-8)');
return $TEXT;
}
1;

View File

@ -0,0 +1,75 @@
<style type="text/css">
.zci--answer .crontab-container {
max-height: 23.3ex;
overflow-y: auto;
}
.zci--answer .crontab-container .crontab-column {
width: 48%;
display: inline-block;
vertical-align:top;
}
.zci--answer .crontab-container .crontab-column:first-child {
margin-right: 3%;
}
.zci--answer .crontab-container p,
.zci--answer .crontab-container .crontab-column {
padding-top: 0;
padding-bottom: 2ex;
}
.zci--answer .crontab-container table {
width: 100%;
}
.zci--answer .crontab-container th {
font-weight: bold;
}
.zci--answer .crontab-container td {
vertical-align: top;
}
.zci--answer .crontab-container dd {
margin-bottom: 1ex;
}
@media(max-width: 704px) {
.zci--answer .crontab-container .crontab-column {
width: 100%;
margin-right: 0;
display: block;
}
}
</style>
<div class="crontab-container">
<div class="crontab-column">
<p>Commands are executed by cron when the minute, hour, and month
fields match the current time, and at least one of the two day fields
(day of month, or day of week) match the current time. A field may be
an asterisk (<code>*</code>), which will always match.</p>
<table>
<tr><th>Field</th><th>Allowed values</th>
<tr><td>minute</td><td>0-59</td></tr>
<tr><td>hour</td><td>0-23</td></tr>
<tr><td>day of month</td><td>1-31</td></tr>
<tr><td>month</td><td>1-12 or first three letters</td></tr>
<tr><td>day of week</td><td>0-7 or first three letters<br>(0 or 7 is Sunday)</td></tr>
</table>
</div>
<div class="crontab-column">
<b>Examples</b>
<dl>
<dt>Run every Tuesday at 2:30</dt>
<dd><code>30 2 * * tue /path/to/command</code></dd>
<dt>Run every 10 minutes</dt>
<dd><code>*/10 * * * * /path/to/command</code></dd>
<dt>Run every 2 hours, on the half hour</dt>
<dd><code>30 */2 * * * /path/to/command</code></dd>
<dt>Run every 2 hours, on the half hour, but only on weekdays</dt>
<dd><code>30 */2 * * 1-5 /path/to/command</code></dd>
<dt>Run at 12:05, 13:05, ..., and 18:05</dt>
<dd><code>5 12-18 * * * /path/to/command</code></dd>
<dt>Run at 12:05, 14:05, 16:05, and 18:05</dt>
<dd><code>5 12-18/2 * * * /path/to/command</code></dd>
<dt>Run on the first day of every month, at midnight</dt>
<dd><code>0 0 1 * * /path/to/command</code></dd>
<dt>Run on the first day of every third month, at midnight</dt>
<dd><code>0 0 1 */3 * /path/to/command</code></dd>
</dl>
</div>
</div>

View File

@ -0,0 +1,37 @@
# Commands are executed by cron when the minute, hour, and month of year
# fields match the current time, and at least one of the two day fields
# (day of month, or day of week) match the current time. A field may be
# an asterisk (*), which will always match.
#
# Fields in order:
# minute (0-59)
# hour (0-23)
# day of month (1-31)
# month (1-12 or first three letters)
# day of week (0-7 or first three letters; 0 or 7 is Sunday)
# Run every Tuesday at 2:30am
30 2 * * tue /path/to/command
# or
30 2 * * 2 /path/to/command
# Run every 10 minutes
*/10 * * * * /path/to/command
# Run every 2 hours, on the half-hour
30 */2 * * * /path/to/command
# Run every 2 hours on the half hour, but only on weekdays
30 */2 * * 1-5 /path/to/command
# Run at 12:05, 13:05, ..., and 18:05
5 12-18 * * * /path/to/command
# Run at 12:05, 14:05, 16:05, and 18:05
5 12-18/2 * * * /path/to/command
# Run on the first day of every month, at 12:00am
0 0 1 * * /path/to/command
# Run on the first day of every third month, at 12:00am
0 0 1 */3 * /path/to/command