DEV Community

kitwharf
kitwharf

Posted on Originally published at kitwharf.com

Stop Pasting Production Crontab Lines into Server-Side Debuggers (Plus flock, GitHub Actions, K8s & AWS EventBridge Exports)

Even senior DevOps engineers still double-check 0 9 * * 1-5 or */15 * * * * before pushing a production schedule. The problem is that many engineers copy an entire line straight out of crontab -e—complete with internal script paths, maintenance windows, or flags—and paste it into a server-side cron debugger that logs query strings and payloads.

Worse, legacy cron testers only give you a raw 5-field string and leave you to manually handle three classic production headaches:

  1. Overlapping Linux cron runs (when a 10-minute backup runs on a 5-minute schedule)
  2. The Unix DOM + DOW OR-Condition Trap (0 0 15 * 5 runs on the 15th and every Friday, not "Friday the 15th")
  3. Cloud syntax fragmentation (GitHub Actions UTC-only YAML, Kubernetes concurrencyPolicy: Forbid, and AWS EventBridge 6-field cron(...) requiring ? in DOM or DOW)

Preventing Overlapping Linux Cron Jobs with flock -n

Native crond never checks whether a previous instance is still running. Wrapping your scheduled command with flock -n guarantees single-instance execution:

0 2 * * * /usr/bin/flock -n /tmp/pg-backup.lock /usr/local/bin/pg-backup.sh >> /var/log/pg-backup.log 2>&1
Enter fullscreen mode Exit fullscreen mode

If /tmp/pg-backup.lock is still held by an earlier run, -n (non-blocking) exits immediately instead of spawning duplicate processes that exhaust RAM.

Converting 5-Field Unix Cron to 6-Field AWS EventBridge

AWS EventBridge rejects standard 5-field cron strings where both Day-of-Month and Day-of-Week are *. One of them must be ?, plus a 6th Year field:

function buildAwsEventBridgeCron(parts: string[]): string {
  const [min, hour, dom, month, dow] = parts;
  let awsDom = dom;
  let awsDow = dow;
  if (awsDom === "*" && awsDow === "*") awsDow = "?";
  else if (awsDom !== "*" && awsDow === "*") awsDow = "?";
  else if (awsDom === "*" && awsDow !== "*") awsDom = "?";
  return `cron(${min} ${hour} ${awsDom} ${month} ${awsDow} *)`;
}
Enter fullscreen mode Exit fullscreen mode

Try It 100% Offline in Browser RAM

We just upgraded the KitWharf Cron Expression Generator & Explainer with:

  • Smart Paste: Paste @daily/@hourly nicknames or full crontab lines (*/15 * * * * /app/backup.sh) directly into the input.
  • Local Time / UTC Toggle: Inspect the next 5 exact fire times in either timezone.
  • DOM + DOW OR-Trap Alert: Live warning whenever both Day-of-Month and Day-of-Week are non-*.
  • 1-Click Ready-to-Deploy Snippets: Switch between Linux + flock, GitHub Actions, K8s CronJob, and AWS EventBridge with one click.

  • Tool: KitWharf Cron Expression Generator

  • Full Guide & Cheat Sheet: How to Write, Read, and Debug Cron Expressions

What's the nastiest cron scheduling bug (DST shift, UTC mismatch, or overlapping job) you've hit in production?

Top comments (0)