From 4781987705d70a860364ed54733e626f711f5817 Mon Sep 17 00:00:00 2001 From: Nathan Korth Date: Tue, 27 May 2014 10:36:10 -0400 Subject: [PATCH 1/7] Added crontab cheat sheet goodie --- lib/DDG/Goodie/CrontabCheatSheet.pm | 58 +++++++++++++++++++ .../crontab_cheat_sheet.txt | 36 ++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 lib/DDG/Goodie/CrontabCheatSheet.pm create mode 100644 share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt diff --git a/lib/DDG/Goodie/CrontabCheatSheet.pm b/lib/DDG/Goodie/CrontabCheatSheet.pm new file mode 100644 index 00000000000..f8d2477bb0f --- /dev/null +++ b/lib/DDG/Goodie/CrontabCheatSheet.pm @@ -0,0 +1,58 @@ +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(), +}; + +sub html_cheat_sheet { + return "
" . text_cheat_sheet() . "
"; +} + +my $TEXT; + +sub text_cheat_sheet { + $TEXT //= share("crontab_cheat_sheet.txt") + ->slurp(iomode => '<:encoding(UTF-8)'); + return $TEXT; +} + +1; diff --git a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt new file mode 100644 index 00000000000..0b1e3118afb --- /dev/null +++ b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt @@ -0,0 +1,36 @@ +# 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. +# +# 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 From da3f78fd40c74f8dffac1a09750fc3bcc4c0954f Mon Sep 17 00:00:00 2001 From: Nathan Korth Date: Sat, 31 May 2014 16:51:04 -0400 Subject: [PATCH 2/7] Created HTML output for CrontabCheatSheet --- lib/DDG/Goodie/CrontabCheatSheet.pm | 6 +- .../crontab_cheat_sheet.html | 69 +++++++++++++++++++ .../crontab_cheat_sheet.txt | 5 +- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html diff --git a/lib/DDG/Goodie/CrontabCheatSheet.pm b/lib/DDG/Goodie/CrontabCheatSheet.pm index f8d2477bb0f..51765068d93 100644 --- a/lib/DDG/Goodie/CrontabCheatSheet.pm +++ b/lib/DDG/Goodie/CrontabCheatSheet.pm @@ -43,8 +43,12 @@ handle remainder => sub { answer => text_cheat_sheet(), }; +my $HTML; + sub html_cheat_sheet { - return "
" . text_cheat_sheet() . "
"; + $HTML //= share("crontab_cheat_sheet.html") + ->slurp(iomode => '<:encoding(UTF-8)'); + return $HTML; } my $TEXT; diff --git a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html new file mode 100644 index 00000000000..42320b49d77 --- /dev/null +++ b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html @@ -0,0 +1,69 @@ + +
+
+

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 (*), which will always match.

+ + + + + + + +
FieldAllowed values
minute0-59
hour0-23
day of month1-31
month1-12 or first three letters
day of week0-7 or first three letters
(0 or 7 is Sunday)
+
+
+

Examples

+
+
Run every Tuesday at 2:30
+
30 2 * * tue /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 midnight
+
0 0 1 * * /path/to/command
+
Run on the first day of every third month, at midnight
+
0 0 1 */3 * /path/to/command
+
+
+
diff --git a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt index 0b1e3118afb..b6ee22bebbe 100644 --- a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt +++ b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.txt @@ -1,6 +1,7 @@ # 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. +# 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) From 9a0cba4fbd0c20290b6a76fd9ce9b9953f94a337 Mon Sep 17 00:00:00 2001 From: Nathan Korth Date: Mon, 2 Jun 2014 16:27:43 -0400 Subject: [PATCH 3/7] More padding between blocks in crontab cheatsheet --- share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html index 42320b49d77..4440a5ab77f 100644 --- a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html +++ b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html @@ -11,6 +11,10 @@ .zci--answer .crontab-container .crontab-column:first-child { margin-right: 4%; } + .zci--answer .crontab-container p, + .zci--answer .crontab-container .crontab-column { + padding-bottom: 2ex; + } .zci--answer .crontab-container table { width: 100%; } @@ -46,7 +50,7 @@
-

Examples

+ Examples
Run every Tuesday at 2:30
30 2 * * tue /path/to/command
From 97e0c06c77dcdae06a3c64946d916b3d63287c05 Mon Sep 17 00:00:00 2001 From: Nathan Korth Date: Mon, 9 Jun 2014 09:41:09 -0400 Subject: [PATCH 4/7] height 36ex --- share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html index 4440a5ab77f..0774a543cf6 100644 --- a/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html +++ b/share/goodie/crontab_cheat_sheet/crontab_cheat_sheet.html @@ -1,6 +1,6 @@