Developer Tools

Cron Expression Syntax and Examples

· QuickToolFlow
cron cron expression cron syntax scheduler devops linux kubernetes github actions

Learn cron expressions with practical examples, syntax explanations, troubleshooting tips, FAQs, and a browser-based cron expression generator.

Table of Contents

  • What Is a Cron Expression?
  • Cron Syntax Explained
  • Cron Special Characters
  • Common Cron Examples
  • Advanced Cron Expressions
  • Where Cron Is Used
  • Linux Cron Tutorial
  • GitHub Actions Cron
  • Kubernetes CronJob
  • Node.js Cron
  • Python Scheduling
  • Cron Best Practices
  • Common Cron Mistakes
  • Cron Cheat Sheet
  • Cron vs Other Scheduling Systems
  • Frequently Asked Questions
  • Free Cron Generator

What Is a Cron Expression?

A cron expression is a scheduling format used to automate recurring tasks.

Cron originated in Unix systems and is now used across:

  • Linux servers
  • Cloud platforms
  • Kubernetes clusters
  • CI/CD pipelines
  • Application schedulers
  • DevOps automation workflows

Instead of manually running repetitive tasks, cron automatically executes commands based on a schedule.

Example:

0 9 * * 1-5

Meaning:

Run every weekday at 9:00 AM.

Typical cron use cases include:

  • Database backups
  • Log cleanup
  • Email notifications
  • Report generation
  • Data synchronization
  • Security scans
  • Cache clearing

Cron Syntax Explained

A standard cron expression contains five fields.

* * * * *
| | | | |
| | | | +-- Day of Week (0-6)
| | | +---- Month (1-12)
| | +------ Day of Month (1-31)
| +-------- Hour (0-23)
+---------- Minute (0-59)

Field Breakdown

FieldAllowed Values
Minute0-59
Hour0-23
Day of Month1-31
Month1-12
Day of Week0-6 (Sunday=0)

Example:

30 14 * * *

Runs every day at 2:30 PM.


Cron Special Characters

Asterisk (*)

Represents every value.

* * * * *

Runs every minute.


Comma (,)

Specifies multiple values.

0 9 * * 1,3,5

Runs on Monday, Wednesday, and Friday.


Hyphen (-)

Defines a range.

0 9-17 * * *

Runs hourly between 9 AM and 5 PM.


Slash (/)

Defines intervals.

*/5 * * * *

Runs every five minutes.


Combined Expressions

1,15,30 * * * *

Specific minutes.

1-10/2 * * * *

Every other value in the range.


Common Cron Examples

Every Minute

* * * * *

Every 5 Minutes

*/5 * * * *

Every 15 Minutes

*/15 * * * *

Every 30 Minutes

*/30 * * * *

Every Hour

0 * * * *

Every 2 Hours

0 */2 * * *

Every Day at Midnight

0 0 * * *

Every Day at 9 AM

0 9 * * *

Weekdays at 9 AM

0 9 * * 1-5

Every Monday at 8 AM

0 8 * * 1

First Day of Every Month

0 0 1 * *

Every Sunday at Midnight

0 0 * * 0

Twice Per Day

0 8,18 * * *

Advanced Cron Expressions

Every Quarter

0 0 1 1,4,7,10 *

Runs on the first day of each quarter.

Business Hours Monitoring

*/15 9-17 * * 1-5

Runs every 15 minutes during business hours.

Every Weekday at 6 PM

0 18 * * 1-5

Useful for reporting jobs.

Last Day of Month

Traditional cron does not support:

L

Some extended schedulers such as Quartz support this feature.


Where Cron Is Used

PlatformUsage
Linuxcrontab
macOScron
KubernetesCronJob
GitHub ActionsScheduled workflows
JenkinsScheduled builds
AWS EventBridgeScheduled events
Azure SchedulerAutomation
Node.jsnode-cron
PythonAPScheduler
LaravelTask Scheduler

Linux Cron Tutorial

Edit cron jobs:

crontab -e

List cron jobs:

crontab -l

Daily backup at 3 AM:

0 3 * * * /home/user/scripts/backup.sh

GitHub Actions Cron

name: Daily Cleanup

on:
  schedule:
    - cron: '0 2 * * *'

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run cleanup

Kubernetes CronJob

apiVersion: batch/v1
kind: CronJob
metadata:
  name: database-backup
spec:
  schedule: '0 2 * * *'

Node.js Cron

const cron = require('node-cron');

cron.schedule('0 0 * * *', () => {
  console.log('Daily cleanup');
});

Python Scheduling

import schedule
import time

def backup():
    print("Running backup")

schedule.every().day.at("03:00").do(backup)

while True:
    schedule.run_pending()
    time.sleep(60)

Cron Best Practices

Use Absolute Paths

Bad:

backup.sh

Good:

/home/user/scripts/backup.sh

Log Everything

0 2 * * * backup.sh >> backup.log 2>&1

Avoid Excessive Frequency

Only use every-minute schedules when truly necessary.

Monitor Job Results

Use:

  • Monitoring tools
  • Alerts
  • Centralized logs

Test Before Production

Validate:

  • Syntax
  • Permissions
  • Runtime environment

Common Cron Mistakes

Timezone Issues

Cron uses the server timezone by default.

Incorrect Field Order

Correct order:

Minute Hour Day Month Weekday

Sunday Differences

Some systems use:

0

Others also support:

7

for Sunday.

Missing Permissions

Ensure scripts are executable.

chmod +x backup.sh

Cron Cheat Sheet

ScheduleExpression
Every minute* * * * *
Every 5 minutes*/5 * * * *
Every hour0 * * * *
Every day0 0 * * *
Every week0 0 * * 0
Every month0 0 1 * *
Every year0 0 1 1 *

Cron vs Other Scheduling Systems

Cron vs systemd Timers

FeatureCronsystemd
Easy to LearnYesModerate
LoggingBasicAdvanced
DependenciesNoYes
Linux NativeYesYes

Cron vs Kubernetes CronJob

FeatureCronCronJob
Cloud NativeNoYes
ScalingLimitedExcellent
Container AwareNoYes

Frequently Asked Questions

What does _/5 _ * * * mean?

It runs every five minutes.

How do I run a cron job every hour?

0 * * * *

Does cron support seconds?

Traditional cron does not support seconds.

What timezone does cron use?

Cron uses the server timezone by default.

Why is my cron job not running?

Common causes:

  • Wrong path
  • Missing permissions
  • Environment variables
  • Timezone mismatch
  • Syntax errors

Try Our Free Cron Generator

Need help building cron schedules?

Use our Cron Expression Generator to:

  • Build schedules visually
  • Validate cron syntax
  • Preview upcoming executions
  • Generate expressions instantly
  • Copy expressions with one click

Related Tools


Conclusion

Cron remains one of the most reliable scheduling systems available. Once you understand the five fields, special characters, and common scheduling patterns, you can automate almost any recurring task with confidence.

For advanced schedules, use a visual Cron Generator to reduce mistakes and improve productivity.

Keep going

Related tools and guides

All tools