More Dynamic Cronjobs

From “you can do that?” to “use real tools” — holiday skips, sunny days, and an AI panic button

TLDR: A clever trick shows you can make scheduled tasks act smarter—skip last Tuesdays, dodge holidays, or run only on sunny days—using simple checks. Commenters split between delight and “use real tools,” swapping picks like Perl App::Cronjob and moreutils’ chronic, and asking for reliable, company-wide holiday data.

Old-school “cronjobs” (think: a computer’s recurring alarm that runs tasks) just got spicier. One tinkerer showed you can bolt simple checks onto the schedule line itself to make jobs smarter—skip the last Tuesday, run only on holidays, only when it’s sunny, or even when an AI says today’s news is on fire. Cue the crowd gasping: “Wait… that works?” The post nods to helpers like Crontab.guru and even leans on the humble POSIX test command for the magic.

The comments turned into a variety show. Some were in awe (“Had no idea!”), while others went enterprise: WolfCop asked for a proper, machine-readable company holiday source, hinting at the real-world mess of global schedules. Tool lovers swooped in: AndrewDavis plugged Perl’s App::Cronjob for features like locking and timeouts—translation: no overlapping chaos—while bblb dropped a mic with “use ‘chronic’ from moreutils,” a cheeky fix for noisy logs. One dev even confessed they’d been writing extra scripts for years when the trick could live right in cron.

The vibe? Friendly chaos. It’s shell wizardry vs. “use a real tool”, but with laughs: dev/null jokes, weather-only errands, and an “AI panic button” that runs your script when the world goes off the rails. Cron, but make it fun.

Key Points

  • Cron’s native syntax can’t express some dynamic schedules (e.g., excluding the last Tuesday), but shell conditionals within crontab entries can.
  • An example uses the Unix date command to compare the current month to the month seven days ahead to skip the last Tuesday at 7am.
  • Platform note: use date -v on macOS/BSD and date -d +7 days on Linux for date arithmetic.
  • Holiday-aware cronjobs can be implemented by fetching US holidays via the Nager.Date API and filtering execution with grep.
  • External data sources like the National Weather Service API and Google News RSS (with an LLM CLI) can gate cron execution based on weather or news conditions.

Hottest takes

“Had no idea you could run commands inside a CRON expression.” — victorbjorklund
“Does anyone maintain a programmatically accessible list of holidays for their company?” — WolfCop
“No more dev nulls.” — bblb
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.