Cron Expression Builder: How to Schedule Tasks with Cron Syntax

DevToolbox

Learn cron expression syntax step by step. Build, test, and validate cron schedules for Linux, Kubernetes, and CI/CD — instantly in your browser.

Cron is the time-based job scheduler in Unix-like systems, and cron expressions are the syntax you use to define when tasks run. Whether you're scheduling database backups, log rotation, or CI/CD pipelines, understanding cron syntax is essential for any developer or system administrator.

This guide walks you through cron expressions from the basics to advanced patterns, with practical examples for every common scheduling scenario. Need to build a cron expression quickly? Our Cron Expression Builder lets you compose and validate schedules visually — right in your browser, with no data leaving your device.

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)
│ │ │ │ ┌───────────── day of week (0-7, where 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Some systems (like Quartz, Spring, and AWS) use a 6-field format that adds seconds:

┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12)
│ │ │ │ │ ┌───────────── day of week (0-7)
│ │ │ │ │ │
* * * * * *

Special Characters

  • * — matches any value (every minute, every hour, etc.)
  • , — list separator (1,3,5 = 1st, 3rd, and 5th)
  • - — range (1-5 = 1 through 5)
  • / — step (*/5 = every 5th value, 0/15 = 0, 15, 30, 45)
  • ? — no specific value (used in day-of-month or day-of-week in 6-field format)
  • L — last (last day of month, last Friday, etc. — Quartz only)
  • W — nearest weekday (Quartz only)
  • # — nth occurrence (5#3 = 3rd Friday — Quartz only)

20 Practical Cron Examples

Basic Schedules

# Every minute
* * * * *

# Every 5 minutes
*/5 * * * *

# Every hour (at minute 0)
0 * * * *

# Every day at midnight
0 0 * * *

# Every day at 9:30 AM
30 9 * * *

Weekly Schedules

# Every Monday at 8:00 AM
0 8 * * 1

# Weekdays at 9:00 AM
0 9 * * 1-5

# Weekends at noon
0 12 * * 0,6

# Every Friday at 5:00 PM
0 17 * * 5

Monthly Schedules

# First day of every month at midnight
0 0 1 * *

# 15th of every month at 3:00 AM
0 3 15 * *

# Last day of the month (using day 28 as safe alternative)
0 0 28 * *

Advanced Patterns

# Every 15 minutes during business hours (9 AM - 5 PM, weekdays)
*/15 9-17 * * 1-5

# Every 6 hours
0 */6 * * *

# Twice a day (8 AM and 8 PM)
0 8,20 * * *

# Every quarter (Jan, Apr, Jul, Oct) on the 1st at midnight
0 0 1 1,4,7,10 *

# Every 30 seconds (6-field format, Quartz/Spring)
*/30 * * * * *

Cron in Different Environments

Linux Crontab

# Edit your crontab
crontab -e

# List current cron jobs
crontab -l

# Example: backup database every day at 2 AM
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

# Example: clear temp files every Sunday
0 3 * * 0 find /tmp -type f -mtime +7 -delete

Important crontab tips:

  • Always use absolute paths — cron jobs run with a minimal $PATH.
  • Redirect output to a log file, or cron will try to email it.
  • Use 2>&1 to capture both stdout and stderr.
  • Set the shell explicitly: SHELL=/bin/bash

GitHub Actions

# .github/workflows/scheduled.yml
name: Scheduled Task
on:
  schedule:
    - cron: '0 9 * * 1-5'  # Weekdays at 9 AM UTC
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./scripts/daily-report.sh

Note: GitHub Actions uses UTC timezone and may have up to 15 minutes of delay for scheduled workflows.

Kubernetes CronJob

apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-cleanup
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cleanup
            image: alpine:latest
            command: ["/bin/sh", "-c", "echo Cleaning up..."]
          restartPolicy: OnFailure

Docker (with supercronic or built-in cron)

# Using supercronic in a Dockerfile
FROM alpine:latest
RUN apk add --no-cache supercronic
COPY crontab /etc/crontab
CMD ["supercronic", "/etc/crontab"]

Common Cron Pitfalls

1. Timezone Confusion

Cron uses the system timezone unless configured otherwise. Cloud services often default to UTC. Always verify which timezone your cron scheduler uses.

2. Overlapping Executions

If a job takes longer than the interval, you'll get overlapping runs. Use file locks (flock) to prevent this:

*/5 * * * * flock -n /tmp/myjob.lock /usr/local/bin/myjob.sh

3. Missing Environment Variables

Cron jobs don't load your shell profile. Environment variables you set in .bashrc won't be available. Define them in the crontab:

PATH=/usr/local/bin:/usr/bin:/bin
DATABASE_URL=postgres://localhost:5432/mydb

0 2 * * * /usr/local/bin/backup.sh

4. Day-of-Month + Day-of-Week Conflict

In standard cron, if both day-of-month and day-of-week are set (not *), the job runs when EITHER condition is met — not both. This is a common source of confusion.

Build Your Cron Expression Now

Our Cron Expression Builder lets you construct cron schedules visually. Select the frequency, adjust the fields, and see a human-readable description of when your job will run. The tool shows the next several execution times so you can verify the schedule is correct.

Everything runs in your browser — no sign-up required, no data sent to any server.

For a quick reference of cron syntax, check our Cron Cheat Sheet. Working with timestamps? The Epoch Converter can help you verify execution times.

Summary

Cron expressions look cryptic at first, but they follow a simple five-field pattern: minute, hour, day-of-month, month, day-of-week. Master the special characters (*, ,, -, /) and you can schedule anything from "every 5 minutes" to "the third Friday of every quarter at 2 AM."

When in doubt, use the DevToolbox Cron Builder to compose, validate, and preview your schedules — instantly and privately.