Axonix Tools
Mastering Cron Jobs: Never Guess the Syntax Again
Back to Insights
DevOpsBackendAutomation

Mastering Cron Jobs: Never Guess the Syntax Again

3 min read

Confused by asterisks? Learn how to schedule tasks effectively with cron syntax without accidentally nuking your database.

I Once Crashed a Production Server With a Single Asterisk

True story. I meant to run a cleanup script once at 5 AM. The correct syntax is 0 5 * * *.

I wrote * 5 * * *.

That one missing zero meant the script ran every single minute from 5:00 to 5:59 AM—60 times instead of once. The script locked the database. Users couldn't log in. I got paged at 5:30 AM.

All because of one character in a 70-year-old scheduling syntax.

Cron Is Ancient Technology (And That's The Problem)

The cron utility was written in 1975. It's been running scheduled tasks on Unix systems for nearly 50 years. That's both impressive and terrifying.

The syntax made sense in an era of limited computing resources and teletypes. Five fields, space-separated, representing minute, hour, day of month, month, day of week. No labels, no hints, no error messages.

According to Stack Overflow's yearly surveys, cron-related questions consistently appear in the top 100 most-asked DevOps questions. We're all confused by this thing.

The Fields Explained (Because I Still Forget)

After 8 years of working with Linux servers, here's my reference:

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *

Common patterns I actually use:

  • 0 5 * * * - Every day at 5:00 AM
  • */15 * * * * - Every 15 minutes
  • 0 0 * * 0 - Every Sunday at midnight
  • 0 9-17 * * 1-5 - Every hour from 9 AM to 5 PM, weekdays only

Why "Silent Failure" Is Cron's Worst Feature

JavaScript throws errors. Python crashes with tracebacks. Cron? Nothing.

If your cron expression is wrong, it just... doesn't run. No error message. No notification. Your backup script silently stops working and you don't notice until you need those backups.

If your expression is syntactically valid but semantically wrong (like my asterisk mistake), it runs too often or at the wrong time. Still no warning.

This is why I never write cron expressions by hand anymore.

The Visual Approach

The Cron Job Generator does bidirectional translation:

Building new schedules:

  1. Select the frequency (daily, weekly, monthly, custom)
  2. Choose your timing (4 PM, Tuesday, first of month)
  3. Get the exact cron syntax

Debugging existing schedules:

  1. Paste a cron expression like */30 9-17 * * 1-5
  2. See plain English: "Every 30 minutes, 9 AM to 5 PM, Monday through Friday"

No more guessing. No more Stack Overflow searches.

Best Practices From Years of Production Experience

Always use absolute paths. Cron doesn't know your shell's PATH. Write /usr/bin/node script.js, not just node script.js.

Log everything. Append >> /var/log/myjob.log 2>&1 to capture output and errors. When something fails, logs are your only clue.

Use which to find binary paths. Run which node or which python3 to get the exact path you need.

Test your commands manually first. Before adding to crontab, run the exact command in your terminal to verify it works.

Consider timezone. Cron uses server time, not your local time. If your server is UTC but you're in New York, 5 AM cron runs at 1 AM Eastern.

Use monitoring. Services like Cronitor or Healthchecks.io will alert you if a scheduled job doesn't run when expected.

The Stakes Are Real

I've seen teams lose weeks of database backups because a cron job silently failed. I've seen runaway scripts cause million-dollar AWS bills because they ran every minute instead of every hour.

Cron syntax isn't just inconvenient—it's a genuine production risk. Use the Generator and eliminate the guessing.

Written by Axonix Team

Axonix Team - Technical Writer @ Axonix

Share this article

Discover More

View all articles

Ready to boost your productivity?

Axonix provides 20+ free developer tools to help you code faster and more securely.

Explore Our Tools