💾 Archived View for tilde.team › ~bh › gemlog › 006_2022-03-19.gmi captured on 2024-05-12 at 15:19:08. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

-=-=-=-=-=-=-

Be careful with `date` and `cron`

One day I write a housekeeping cron job to update me frequently with the status of one of my proxy. Basically I want to put a timestamp on the status report, so I naively put `date +%Y-%b-%d` in the expectation that it will print the date at the time the cron job run.

The result was unexpected, the cron job never run. I scratched my head and tried to do anything within my experience, executing the command from a script and in an Almquish shell, eveything was fine, except when putting it in a cron job.

After a day and a half, I came across a search result that debunk the whole case for me. The character percent `%` need to be escaped (by a backslash `\`) in cron, because percent `%` is a special character to allow the "input" into cron "command" (sixth parameter). So the command that will print the datetime in cron must be `date +\%Y-\%b-\%d`

But there are more than one implementation and more than one version of each implementation of cron, and in each implementation/version, the crontab manpage is written differently. The description can be found from "ISC Cron" `https://linux.die.net/man/5/crontab`, but some of my nodes use "Vixie Cron" and there's no way I can find this information in the manpage.