From 29d276ae44cf4d8c5e0ab40b2973fd6384ff5257 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Mon, 5 Jan 2026 20:58:35 +0100 Subject: [PATCH] chore(kb/cron): add warning about quoting the percent char --- knowledge base/cron.md | 2 ++ knowledge base/crontab.md | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/knowledge base/cron.md b/knowledge base/cron.md index 3dfe569..67ee9a5 100644 --- a/knowledge base/cron.md +++ b/knowledge base/cron.md @@ -31,6 +31,8 @@ All crontab files: - Must be either regular files or symlinks to regular files. - Must **not** be executable **nor** writable for anyone else but the owner.
This requirement can be overridden by using the `-p` option on `crond`'s command line. +- Must escape the `%` character in commands, if used (e.g., in `date`'s formatting).
+ Cron interprets `%` as a newline. Everything after it is sent to the command's stdin, not as part of the command. > [!important] > If `inotify` support is in use, changes in symlinked crontabs are **not** automatically noticed by the cron daemon. diff --git a/knowledge base/crontab.md b/knowledge base/crontab.md index cc470b7..9da92eb 100644 --- a/knowledge base/crontab.md +++ b/knowledge base/crontab.md @@ -6,6 +6,10 @@ ## TL;DR +> [!caution] +> Escape the `%` character if used in commands (e.g., in `date`'s formatting), even if in quotes.
+> Cron interprets `%` as a newline. Everything after it is sent to the command's stdin, not as part of the command. + ```sh # List existing jobs. crontab -l @@ -35,7 +39,9 @@ sudo crontab -r -u 'nana' */10 * * * * ls # Run a script at 02:34 every Friday. +# `%` needs escaping even in quotes 34 2 * * Fri /absolute/path/to/script.sh +35 3 * * FRI /absolute/path/to/script.sh > /absolute/path/to/script.$(date '+\%F').log ``` ## Further readings