TL;DR
You can extend crontab behavior by inserting short shell tests so jobs run only under specific, changing conditions. Examples include skipping the month's last Tuesday, avoiding holidays from a downloaded list, or running only when weather or news conditions match a query.
What happened
The author revisited cronjob scheduling and showed how to add small shell-based conditionals directly into crontab lines to implement rules the native cron pattern language can't express. For example, to run a task every Tuesday at 7am except when that Tuesday is the month's last, run the job every Tuesday but precede it with a date check that compares the month for today and seven days ahead. The post explains the brackets are the POSIX test command and notes platform differences in the date utility (macOS/BSD uses -v while Linux uses -d). Additional examples demonstrate fetching a list of public holidays with curl and jq to skip runs, querying the National Weather Service for forecast text to only run on clear or cloudy hours, and piping a news RSS feed into an LLM that returns a yes/no signal to decide whether to run an emergency script.
Why it matters
- Gives operators a simple way to express dynamic scheduling conditions without replacing cron with another scheduler.
- Reduces unnecessary runs by gating execution on external data (date math, holiday lists, weather, news).
- Uses standard shell tools and small one-liners, keeping logic close to the crontab entry.
- Requires attention to platform differences in common utilities (e.g., date flags).
Key facts
- Cron's pattern syntax cannot natively express some dynamic rules, such as "every Tuesday except the last one of the month."
- You can prepend a test to a crontab entry; the POSIX test command is commonly written with square brackets or as the test utility.
- Example to skip the last Tuesday: 0 7 * * Tue [ "$(date -v+7d '+%m')" = "$(date '+%m')" ] && /path/to/your_command
- On macOS/BSD the date utility uses -v+7d; on Linux the equivalent is typically -d +7 days (platform-specific detail noted).
- Fetch a yearly list of US public holidays via curl and jq: curl -s https://date.nager.at/api/v3/PublicHolidays/2025/US | jq -r '.[].date' > HOLIDAYS.txt
- Use grep -qx against HOLIDAYS.txt inside the crontab line to skip or run jobs on holidays (examples given for both cases).
- Weather gating example uses the National Weather Service hourly forecast endpoint piped through jq and grep to match forecast text like 'clear' or 'cloudy'.
- A suggested news-based example pipes an RSS feed into an LLM invoked as llm to get a binary yes/no decision, then conditionally runs a script.
What to watch next
- Platform differences in core utilities (for example, date's -v on macOS/BSD vs -d on Linux) — confirmed in the source.
- Reliance on external services (holiday API, weather API, RSS feeds) and their availability — not confirmed in the source.
- Potential implications for rate limits or API keys when polling third-party services frequently — not confirmed in the source.
Quick glossary
- cron / crontab: A time-based job scheduler on Unix-like systems; crontab files define scheduled commands and their run times.
- POSIX test: A shell builtin or utility (often written with [ ] brackets) that evaluates expressions and returns true/false for conditional execution.
- jq: A command-line JSON processor used to extract or transform fields from JSON output.
- RSS: A simple XML-based format for distributing news and updates from websites that can be consumed by programs or scripts.
Reader FAQ
Can crontab itself express rules like "not the last Tuesday"?
Not with its scheduling syntax alone; the source shows adding a shell test to a crontab entry to implement that rule.
Do the date command flags vary across systems?
Yes — the post notes macOS/BSD uses -v+7d while Linux typically uses -d +7 days.
Are the provided one-liners production-ready and secure?
Not confirmed in the source.
Can you gate cronjobs on external data like weather or news?
Yes — the article demonstrates examples using the National Weather Service and an RSS-to-LLM pipeline to decide whether to run a job.

More dynamic cronjobs September 21st, 2025 • ~600 words • 3 minute read I remember learning about cronjobs in the early 2000s. I could tell the computer to go do…
Sources
- More dynamic cronjobs
- How do I create a crontab through a script
- cron – Dynamic crontab file?
- Add something to crontab programmatically (over ssh)
Related posts
- Inside the Proton — Unraveling the Most Complicated Thing Known
- Ez FFmpeg — Plain-English CLI for common ffmpeg video edits and tasks
- Inside the Proton — the ‘Most Complicated Thing You Could Possibly Imagine’