A cron expression is a compact five-field string that defines when a scheduled job should run: minute, hour, day of month, month, and day of week. The standard format is * * * * *, where each asterisk is a wildcard that can be replaced with specific numbers, ranges, lists, or step values. Writing these expressions manually requires memorizing the exact field order and syntax rules, which vary slightly between schedulers like Linux crontab, Kubernetes CronJobs, and cloud platforms. Instead of guessing or looking up the order every time, you can use a browser-based Cron Expression Generator to build the expression from a readable schedule.

Whether you need to run a backup script every night at 2 AM, clean up logs every Monday at noon, or trigger a database sync on the first day of each month, the generator lets you pick the frequency and set the exact time without worrying about field order. You start by choosing a schedule type—hourly, daily, weekly, monthly, yearly, or custom—then adjust the interval, minute, hour, weekday, or month day shown for that schedule. The tool immediately updates the five-field expression, which you can copy and paste directly into your scheduler. This approach eliminates syntax errors and saves time, especially when you need to create multiple jobs with different frequencies.

Cron expressions are used in many environments, from local Linux servers to cloud platforms like Kubernetes, AWS CloudWatch, and Google Cloud Scheduler. Each environment may interpret the fields slightly differently, especially around edge cases like day-of-week versus day-of-month conflicts or time zone handling. For example, Kubernetes CronJobs use UTC by default, while Linux crontab uses the system’s local time zone. The generator outputs a standard five-field expression, but you should always verify it in your target scheduler and confirm the time zone matches your expectations. The tool also runs entirely in your browser, so no schedule details are sent to a server, keeping your job definitions private.

how to create a cron job
how to create a cron job

How Cron Expressions Work

Cron expressions consist of five fields separated by spaces. Each field can contain numbers, wildcards, ranges, lists, or step values. Here’s what each field represents:

Field Allowed Values Special Characters Example
Minute 0–59 *, ,, -, / 0, 0,30, */15
Hour 0–23 *, ,, -, / 2, 8-17, */2
Day of Month 1–31 *, ,, -, /, ? 1, 15,30, L
Month 1–12 or JAN–DEC *, ,, -, / 1, JAN,JUN,DEC, */3
Day of Week 0–7 (0 and 7 are Sunday) or SUN–SAT *, ,, -, /, ?, L, # 0, MON-FRI, 5L

The wildcards and special characters let you create flexible schedules. For example, */5 * * * * runs a job every 5 minutes, while 0 0 1 * * runs it at midnight on the first day of every month. Some schedulers, like Kubernetes, support an optional sixth field for the year, but the generator focuses on the standard five-field format used by most systems.

Create a Cron Expression in Three Steps

To build a cron expression without memorizing field order, follow these steps using the Cron Expression Generator:

  1. Choose the schedule type: Select the frequency that matches your job. The options are:

    • Hourly: Run every X hours at a specific minute.
    • Daily: Run every day at a specific time.
    • Weekly: Run on specific weekdays at a specific time.
    • Monthly: Run on specific days of the month at a specific time.
    • Yearly: Run on a specific month and day at a specific time.
    • Custom: Manually set each field for advanced schedules.
  2. Set the interval and time: Adjust the controls shown for your chosen schedule type. For example:

    • For an hourly job, set the minute (e.g., 0 for the top of the hour) and the interval (e.g., every 2 hours).
    • For a weekly job, pick the weekday (e.g., Monday) and the time (e.g., 14:30).
    • For a monthly job, pick the day of the month (e.g., 1st, 15th, or last day) and the time.

    The tool updates the five-field expression in real time as you adjust the controls.

  3. Copy and verify the expression: Once the expression matches your schedule, copy it to your clipboard. Before pasting it into your scheduler, verify it in the target environment. For example:

    • In Linux crontab, run crontab -e and paste the expression followed by the command.
    • In Kubernetes, create a CronJob manifest and set the schedule field to your expression.
    • In cloud platforms like AWS or Google Cloud, paste the expression into the scheduler’s configuration panel.

    Always check the time zone settings in your scheduler to ensure the job runs at the expected local time.

Common Cron Job Use Cases

Cron jobs automate repetitive tasks across many environments. Here are some common use cases and their corresponding cron expressions, generated using the tool:

Use Case Schedule Type Cron Expression
Run a backup script every night at 2 AM Daily 0 2 * * *
Clean up temporary files every Monday at noon Weekly 0 12 * * 1
Sync a database on the 1st and 15th of every month at 3 AM Monthly 0 3 1,15 * *
Check for system updates every 6 hours Hourly 0 */6 * * *
Generate a monthly report on the last day of each month at 11 PM Monthly 0 23 L * *
Send a reminder email every weekday at 9 AM Weekly 0 9 * * 1-5

These examples show how the generator simplifies creating expressions for common schedules. For more complex scenarios, like running a job every 10 minutes on weekdays between 9 AM and 5 PM, you can use the custom schedule type to manually set each field. The tool’s real-time feedback helps you avoid syntax errors and ensures the expression matches your intent.

Verify and Test Your Cron Expression

After generating a cron expression, it’s important to verify it in your target scheduler before relying on it. Here’s how to test it in different environments:

  • Linux crontab: Run crontab -e to edit your user’s crontab file. Add a line with your expression followed by a command that logs output, such as:

    0 2 * * * /path/to/backup.sh >> /var/log/backup.log 2>&1

    Check the log file after the scheduled time to confirm the job ran.

  • Kubernetes CronJob: Create a YAML manifest with your expression in the schedule field. For example:

    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: backup
    spec:
      schedule: "0 2 * * *"
      jobTemplate:
        spec:
          template:
            spec:
              containers:
              - name: backup
                image: busybox
                command: ["/bin/sh", "-c", "echo Backup completed at $(date)"]
              restartPolicy: OnFailure

    Apply the manifest with kubectl apply -f backup.yaml and check the job’s status with kubectl get cronjobs and kubectl get jobs.

  • Cloud platforms: In AWS CloudWatch Events, Google Cloud Scheduler, or Azure Logic Apps, paste the expression into the scheduler’s configuration panel. Most platforms provide a preview of the next few run times, which you can use to verify the schedule. For example, AWS CloudWatch Events shows the next 10 trigger times when you save the rule.

Time zone handling is a common source of confusion. Linux crontab uses the system’s local time zone by default, while Kubernetes CronJobs use UTC. The generator outputs the expression in UTC, so if your scheduler uses a different time zone, you may need to adjust the hour field accordingly. For example, if you want a job to run at 2 AM local time in a UTC+2 time zone, set the hour field to 0 (midnight UTC) in the generator.

For debugging, you can use tools like Unix Timestamp Converter to check the exact time a cron expression will trigger. Convert the next expected run time to your local time zone to confirm it matches your schedule. If the job doesn’t run as expected, check the scheduler’s logs for errors. In Linux, cron logs are typically found in /var/log/syslog or /var/log/cron, while Kubernetes logs can be viewed with kubectl logs.

Advanced Cron Expression Features

While the generator covers most common schedules, some advanced use cases require manual adjustments to the expression. Here are a few features supported by many schedulers:

  • Step values: Use the / character to run a job at regular intervals within a range. For example, */15 * * * * runs a job every 15 minutes, while 0 9-17/2 * * * runs it every 2 hours between 9 AM and 5 PM.

  • Ranges and lists: Use the - character to specify a range (e.g., 1-5 for Monday to Friday) and the , character to specify a list (e.g., 1,15 for the 1st and 15th of the month).

  • Last day of the month: Use L in the day-of-month field to run a job on the last day of the month. For example, 0 0 L * * runs it at midnight on the last day of every month.

  • Day of week with offset: Use # to specify the Nth occurrence of a weekday in a month. For example, 0 0 * * 1#3 runs a job at midnight on the third Monday of every month.

  • Question mark for no specific value: Use ? in the day-of-month or day-of-week field to indicate no specific value. This is useful when you want to specify one field but not the other. For example, 0 0 1 * ? runs a job on the 1st of every month, regardless of the weekday.

Not all schedulers support these advanced features, so check your scheduler’s documentation before using them. The generator supports step values, ranges, and lists for all schedule types, but you may need to switch to the custom schedule type to use L, #, or ?.

For complex schedules that don’t fit into the standard five-field format, consider breaking the job into multiple cron expressions or using a script to handle the logic. For example, if you need to run a job every 10 minutes on weekdays but only once per hour on weekends, you can create two separate cron jobs with different expressions:

*/10 * * * 1-5 /path/to/job.sh
0 * * * 0,6 /path/to/job.sh

This approach keeps the expressions simple and easy to maintain. The generator can help you create both expressions quickly, even for multi-part schedules.

Related guide: How to Check if Your JSON Format Is Correct.

If you're weighing options, Remove BOM from CSV Files Without Losing Data covers this in detail.