From: Matt Amos Date: Wed, 5 Aug 2020 11:02:21 +0000 (+0100) Subject: Fix escaping in old-planet-file-cleanup cron rule. X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/7281c19b460c7002d8bd5d24f8bf6c937494d4e4 Fix escaping in old-planet-file-cleanup cron rule. The old planet file cleanup cron rule is intended to run on the first Monday of each month. Unfortunately, this is slightly difficult to write because cron triggers on [either the day-of-month or day-of-week](https://linux.die.net/man/5/crontab) fields, not both. The fix suggested in the man page is to use a `test $(date %u) -eq 1 &&` to filter the command execution. However, to make things more complicated, the percent sign is a special character for cron (it's an escaped newline) and regular uses of `%` must be backslash escaped. Long story short, the `date \%u` in the template file needs an extra `\` if it is to be used in a quoted Ruby string. (Although it would be nice if the `cron_d` resource handled proper escaping to avoid cron's `%`-related footguns, apparently it passes the string through unmodified.) --- diff --git a/cookbooks/planet/recipes/default.rb b/cookbooks/planet/recipes/default.rb index 0f505af06..b99b4ab0b 100644 --- a/cookbooks/planet/recipes/default.rb +++ b/cookbooks/planet/recipes/default.rb @@ -127,6 +127,6 @@ cron_d "old-planet-file-cleanup" do hour "3" day "1-7" user "www-data" - command "test $(date +\%u) -eq 1 && /usr/local/bin/old-planet-file-cleanup --debug" + command "test $(date +\\%u) -eq 1 && /usr/local/bin/old-planet-file-cleanup --debug" mailto "zerebubuth@gmail.com" end