30 January,2014 by Tom Collins
Question: How do I schedule a cron job (or crontab job) for for the first Sunday of every month?
Answer: To schedule a job to run on the first Sunday of every month , use the crontab example as a template.
This example executes a script at 2am on a Sunday where the day of the month is between 1 and 7. Adjust according to your needs
Before we look at a solution - a couple of notes around potential gotchas when it comes to creating a cron job
The relationship between day of month and day of week fields are OR , not AND. I have been caught out by this previously.
00 02 1-7 * * [ "$(date '+\%a')" == "Sun" ] && /usr/local/bin/once_a_mth_first_Sunday --every Sunday of first 7 days of the month , --cron reference --min --hour --day of month --month --day of week
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |