chore(kb/cron): add warning about quoting the percent char

This commit is contained in:
Michele Cereda
2026-01-05 20:58:35 +01:00
parent 2abfe7402c
commit 29d276ae44
2 changed files with 8 additions and 0 deletions

View File

@@ -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.<br/>
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).<br/>
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.

View File

@@ -6,6 +6,10 @@
## TL;DR
> [!caution]
> Escape the `%` character if used in commands (e.g., in `date`'s formatting), even if in quotes.<br/>
> 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