Crontab Explainer

Parse cron expressions with human-readable text and next run times.

Free Online Crontab & Cron Expression Explainer

Cron expressions like 0 */5 * * * are compact but cryptic. Dokall translates any valid cron expression into human-readable text and shows upcoming run times so you can verify schedules before deploying.

DevOps engineers and backend developers use this tool to double-check scheduled jobs, debug timing issues, and document cron configurations for the team.

What is Cron?

Cron is a time-based job scheduler in Unix-like operating systems. It runs commands or scripts automatically at scheduled times - every minute, every day at midnight, every Monday at 9 AM, or any other schedule you can express. The cron daemon runs in the background and checks the schedule every minute.

Each user has a crontab (cron table) file that lists their scheduled jobs. System-wide cron jobs live in /etc/crontab and /etc/cron.d/. The cron system is fundamental to server administration - it handles log rotation, backups, database maintenance, email reports, cache clearing, and countless other automated tasks.

Cron Expression Format

A standard cron expression has five fields separated by spaces: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7, where 0 and 7 are both Sunday).

Each field can be a specific value (5), a range (1-5), a list (1,3,5), a step (*/5), or an asterisk (*) meaning all values. The expression 30 2 * * 1 means "at 2:30 AM on Monday". The expression 0 */4 * * * means "at minute 0, every 4th hour" (midnight, 4 AM, 8 AM, noon, 4 PM, 8 PM).

Some cron implementations (like Quartz) add a sixth field for seconds and a seventh for year. AWS CloudWatch Events and GitHub Actions use a slightly different syntax. This tool parses standard 5-field Unix cron expressions.

Special Characters in Cron Expressions

The asterisk (*) means "every". * in the hour field means every hour. * in the day-of-week field means every day.

The comma (,) separates list values. 1,3,5 in the day-of-week field means Monday, Wednesday, and Friday.

The hyphen (-) defines ranges. 9-17 in the hour field means every hour from 9 AM through 5 PM.

The slash (/) defines steps. */5 in the minute field means every 5th minute (0, 5, 10, 15...). 1-30/2 means every 2nd minute from 1 through 30 (1, 3, 5, 7...).

Some implementations support additional characters: L (last day of month), W (nearest weekday), # (nth weekday of month, e.g. 2#1 = first Monday), and ? (no specific value, used when the other day field is specified).

Common Cron Schedules

Every minute: * * * * * - useful for health checks and real-time monitoring, but consider the load.

Every 5 minutes: */5 * * * * - a common interval for polling, cache updates, and queue processing.

Every hour: 0 * * * * - runs at minute 0 of every hour. Good for hourly reports and data syncs.

Daily at midnight: 0 0 * * * - the classic daily job for backups, log rotation, and reports.

Every weekday at 9 AM: 0 9 * * 1-5 - runs Monday through Friday. Common for business-hour tasks and daily notifications.

First day of every month: 0 0 1 * * - runs at midnight on the 1st. Good for monthly billing, reports, and cleanup.

Every Sunday at 2 AM: 0 2 * * 0 - weekly maintenance window. Pick a time with low traffic.

Cron Best Practices

Always redirect output to a log file: */5 * * * * /path/to/script.sh >> /var/log/myjob.log 2>&1. Without redirection, cron sends output via email (or drops it silently if mail is not configured), and you lose debugging information.

Use absolute paths for commands and files. Cron runs with a minimal environment - your PATH may not include /usr/local/bin or other directories you use in interactive shells. Specify the full path or set PATH at the top of the crontab.

Add error handling and locking. If a job runs longer than the interval, the next invocation starts while the first is still running. Use flock or a PID file to prevent overlapping: * * * * * flock -n /tmp/myjob.lock /path/to/script.sh.

Test the schedule before deploying. Paste your cron expression into this explainer to verify the next run times match your expectation. A common mistake is confusing day-of-month and day-of-week fields.

Monitor your cron jobs. Use a cron monitoring service (Cronitor, Healthchecks.io) that alerts you when a scheduled job fails to run or takes too long.

Frequently Asked Questions

What is the difference between cron and crontab?
Cron is the daemon (background service) that executes scheduled commands. Crontab (cron table) is the configuration file where you define the schedule. The crontab command is also used to edit the file: crontab -e opens your crontab for editing, crontab -l lists current entries, and crontab -r removes all entries.
How do I run a cron job every 5 minutes?
Use the expression */5 * * * * followed by your command. The */5 in the minute field means "every 5th minute" - the job runs at :00, :05, :10, :15, :20, :25, :30, :35, :40, :45, :50, and :55 of every hour.
What does */5 mean in a cron expression?
The slash (/) is a step value. */5 means "every 5th value starting from the minimum". In the minute field (range 0-59), */5 expands to 0,5,10,15,20,25,30,35,40,45,50,55. In the hour field (range 0-23), */5 expands to 0,5,10,15,20. You can also use a range with a step: 1-30/5 means every 5th minute from 1 through 30.
How do I edit my crontab?
Run crontab -e in your terminal. This opens your crontab file in the default text editor (usually vi or nano). Add one job per line in the format: minute hour day-of-month month day-of-week command. Save and exit - cron picks up changes immediately. Run crontab -l to verify your entries.
Can cron run a job every second?
No. The minimum granularity of standard cron is one minute. To run a job every second, you need a different approach: a loop in a script (while true; do command; sleep 1; done), systemd timers with OnUnitActiveSec=1s, or a process supervisor. For most use cases, if you need sub-minute scheduling, cron is not the right tool.
What happens if a cron job takes longer than the interval?
Cron starts a new instance regardless - it does not check if the previous run is still going. This can cause overlapping executions, resource contention, and data corruption. Prevent this with file locking: flock -n /tmp/myjob.lock /path/to/script.sh. The -n flag makes flock exit immediately if the lock is held, skipping the overlapping run.
How do I debug a failing cron job?
First, check cron logs: grep CRON /var/log/syslog (Ubuntu) or /var/log/cron (CentOS). Redirect your job's output to a file: * * * * * /path/to/script.sh >> /tmp/debug.log 2>&1. Common issues: wrong PATH (use absolute paths), permission errors (the cron user may differ from your shell user), and missing environment variables (cron runs with a minimal environment).