TechCompare LogoTechCompare

How to run a cron job weekly: Sunday midnight and other weekly patterns

0 0 * * 0 for weekly Sunday execution is the safest portable choice. If weekday numbering ambiguity matters (containers, embedded systems), test the expression on the target cron daemon before deploying to production.

0 0 * * 0 runs a job every Sunday at midnight. The fifth field (0-6 or 0-7 depending on the cron implementation) controls the day of the week. Sunday is 0 (and sometimes 7), Monday is 1, Saturday is 6. This is the pattern for weekly reports, SSL certificate renewal checks, and full backups.

By TechCompare · Updated

Schedule pattern
Weekly schedule
weekly
Category
Common Patterns
Standard cron expression patterns

How this is calculated

Different cron implementations number weekdays differently. Vixie cron (standard Linux) uses 0-7 where both 0 and 7 are Sunday. BusyBox cron uses 0-6 where 0 is Sunday. Some enterprise schedulers use 1-7 where 1 is Monday. When writing portable cron expressions, avoid relying on 7 for Sunday. For multiple days, list or range them: 0 0 * * 1-5 runs Monday through Friday. For every other day, cron alone can't express that cleanly. Use a wrapper script that checks the date.

Verdict

Day-of-week numbering is where cron stops being portable. Vixie cron treats both 0 and 7 as Sunday, BusyBox only accepts 0-6, and enterprise schedulers sometimes start at Monday=1. Listing Monday through Friday as 1-5 reads cleanly, but never rely on 7 for Sunday across mixed systems. Testing the expression on the actual cron daemon is the only reliable check.

More Cron scenarios

Frequently asked questions

How do I run a cron job once a week?
Use 0 0 * * 0 for Sunday at midnight. The fifth field is the day of week, numbered 0-6 (or 0-7 on many Linux crons, where both 0 and 7 mean Sunday). Monday is 1, Saturday is 6. Weekly reports, certificate renewal checks, and full backups are the typical weekly jobs.
Is Sunday 0 or 7 in cron?
Both on Vixie cron and cronie, which accept 0-7 with 0 and 7 both mapping to Sunday. BusyBox cron (Alpine Linux, minimal containers) only accepts 0-6, and a few enterprise schedulers start the week at Monday=1. For portable expressions, always use 0 for Sunday and never rely on 7.
How do I run a cron job on weekdays only?
Use a range in the day-of-week field: 0 9 * * 1-5 runs at 9 AM Monday through Friday. Multiple specific days work with a comma list, like 0 9 * * 1,3,5 for Monday, Wednesday, and Friday. The day-of-week and day-of-month fields combine with OR logic, so be careful mixing them - 0 0 1 * 1 runs on the 1st of the month and every Monday.