0 0 * * 0 runs the job once a week, on Sunday at 0:00. The last field selects the weekday, and cron counts Sunday as 0; writing 7 there means exactly the same day. The shortcut @weekly expands to this very line, which is why weekly maintenance traditionally lands in the small hours of Sunday.
Is Sunday 0 or 7 in cron?
Both. The weekday field accepts values from 0 to 7, and 0 and 7 are the same day. That is why the range 0-6 already covers the whole week and why a range like 5-7 works out as Friday, Saturday and Sunday. Ranges that wrap around, such as 6-1 for the weekend plus Monday, are not allowed — write 6,0,1 instead.
Sunday at midnight — is that the start or the end of the week?
For cron it is simply the moment when the weekday becomes Sunday, that is Saturday night rolling into Sunday. In Germany the week officially starts on Monday under ISO 8601, so a weekly report that runs at Sunday 0:00 summarises a week that is not over yet. If you want the completed week, schedule 0 3 * * 1 on Monday morning instead.
What is a weekly schedule good for?
For everything that is too expensive to run daily: full backups next to the daily incremental ones, database maintenance, index rebuilds, reports for a whole week, cleaning out old temporary files. The long gap makes monitoring more important, not less — a weekly job that fails silently is only noticed a week later, so log the exit code.
How to add the expression
- Decide which weekday fits: 0 for Sunday night, 1 for Monday morning when you want the completed week.
- Add 0 0 * * 0 plus the command, or @weekly if the schedule is unlikely to change.
- Pick a quiet hour if the job is heavy; Sunday 3 a.m. is emptier than Sunday midnight.
- Write the exit code to a log so a failed weekly run does not go unnoticed for seven days.