Run a cron job once a week

Choose a weekday and time, understand @weekly, and avoid treating week-number parity as a reliable two-week schedule.

Best practices
Illustration of scheduled jobs, logs and Linux operations

Set the fifth time field to the weekday you want. For Sunday at midnight, use:

0 0 * * 0 /opt/jobs/weekly.sh

The fields are minute, hour, day of month, month and day of week. Here the day-of-month and month wildcards leave the weekday restriction to choose Sundays.

Choose the weekday and time

Common Vixie-derived cron implementations accept 0 or 7 for Sunday, 1 for Monday, through 6 for Saturday. Many also accept names such as mon and sun; check the local manual if portability matters.

Schedule Expression
Sunday at midnight 0 0 * * 0
Monday at 04:30 30 4 * * 1
Thursday at 22:00 0 22 * * 4
Monday and Thursday at midnight 0 0 * * 1,4

Add the command after the expression. These are user-crontab examples; system cron files also require a username.

Use @weekly when its fixed time suits you

On implementations supporting the macro:

@weekly /opt/jobs/weekly.sh

This conventionally means Sunday at midnight, equivalent to 0 0 * * 0. It does not mean seven days after installation or seven days after the previous run finished. Other common macros include @daily, @hourly, @monthly and @reboot, but their availability is implementation-specific.

Do not assume another scheduler uses the same convention. For example, systemd's weekly calendar shorthand means Monday at midnight.

Plan for timezone and missed runs

Traditional cron schedules use the daemon's timezone unless the implementation supports a per-table override such as Cronie's CRON_TZ. Setting a job's TZ environment variable alone does not universally change its scheduled time. Clock changes and daylight saving behavior also vary by implementation.

Ordinary cron does not generally replay jobs missed while the machine was off. If catch-up matters, consider anacron or an appropriate persistent calendar timer and make the application safe to retry.

Save output to a file the job account can write:

30 4 * * 1 /opt/jobs/weekly.sh >> /var/log/jobs/weekly.log 2>&1

Record completion and the business period processed. Because a weekly job has a long interval, alert against its expected completion window, allowing for normal runtime and log delivery delay. A launch message alone is insufficient.

Common questions

Are Sunday values 0 and 7 equivalent? They are in common Vixie-derived implementations. Choose one convention for your team and verify it in other cron dialects.

Can I run every other week? A single traditional cron expression does not represent an anchored fourteen-day cadence. ISO week-number parity breaks across some year boundaries and is not a dependable substitute. Use a daily/weekly guard based on a fixed calendar anchor or a scheduler that explicitly supports the recurrence, and define missed-run behavior.

There is no record on Sunday. What next? Check the daemon's schedule timezone and availability, its launch logs, the script's output destination, and collection health. A missing centralized log does not by itself prove the job never ran.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting