]> git.openstreetmap.org Git - chef.git/commit
Fix escaping in old-planet-file-cleanup cron rule.
authorMatt Amos <zerebubuth@gmail.com>
Wed, 5 Aug 2020 11:02:21 +0000 (12:02 +0100)
committerMatt Amos <zerebubuth@gmail.com>
Wed, 5 Aug 2020 11:02:21 +0000 (12:02 +0100)
commit7281c19b460c7002d8bd5d24f8bf6c937494d4e4
treecf4e7ef2d08ebe7eaa572a41edbd89c928629117
parentd9fa88b9a3e164150d60ed750c13df4a342d6de9
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.)
cookbooks/planet/recipes/default.rb