What is a cron job and how do you write a cron expression?

Short answer
A cron job is a scheduled task that runs automatically at specified times on Unix-like systems. The schedule is defined by a cron expression - a five-field string representing minute, hour, day of month, month, and day of week. For example, '0 9 * * 1' runs a task at 9:00 AM every Monday. Cron is used for automated backups, database cleanup, report generation, cache warming, and any recurring server-side task.

Cron has been a Unix staple since 1975 and remains the most common scheduling mechanism for server-side automation. On Linux and macOS, cron jobs are configured in a crontab file managed with the crontab -e command. Many modern platforms (AWS EventBridge, GitHub Actions, Vercel, Railway) implement the same cron expression syntax for their own schedulers, so the knowledge transfers broadly.

A standard cron expression has five space-separated fields: [minute] [hour] [day-of-month] [month] [day-of-week]. Each field accepts a specific value, a wildcard (*), a range (1-5), a step value (*/15 meaning every 15 units), or a comma-separated list (1,3,5). Some extended implementations add a sixth field for seconds.

Reading common expressions becomes intuitive quickly. * * * * * - runs every minute. 0 * * * * - runs at the top of every hour. 30 6 * * * - runs at 6:30 AM every day. 0 0 1 * * - runs at midnight on the first day of every month. 0 8-18 * * 1-5 - runs at the top of every hour from 8am to 6pm on weekdays only.

The most common pitfalls: cron uses the system timezone, which may differ from your application's timezone - always check or set TZ explicitly. Cron does not retry failed jobs; if a job fails silently, you will not know unless you implement logging or alerting. Jobs that run longer than their interval overlap unless you implement locking (flock on Linux, or application-level locks).

A cron expression generator lets you build and validate expressions visually, describing the schedule in plain English before committing the string to production configuration.

Try the tool

Cron BuilderCron Tester
Reviewed by Searchlight · Last reviewed