Cron job - Need to run Cron every quarter at particular time

Hi,

1)
If some job supposed to run on 1st of every month at 7 AM
In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day?

2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct)
And if 25th falls on Sunday, how can we make it work next business day.

Thank you,

See man crontab . crontab entry for

1)
0 7 1 * * jobscript1
2)
0 7 25 1,4,7,10 * jobscript2

In the respective script, test for Sundays, e.g. like [ $(date +%u) -eq 7 ] && sleep 86400 . This will not work across reboots.

1 Like

For the first:

0 8 1 * * [[ `date +%a` != @(Sat|Sun) ]] && command
0 8 2,3 * * [[ `date +%a` == Mon ]] && command

(adjust weekday names for your locale)

For the second:

0 7 25 1,4,7,10 * [[ `date +%a` != Sun ]] && command
0 7 26 1,4,7,10 * [[ `date +%a` == Mon ]] && command

Please be aware that cron assumes the system is always running.

3 Likes

Thanks for pointing out the conflict between my line/case numbering and the crontab lines themselves. I corrected that in the post for clearer readability.

RudiC, nothing wrong with your posting, I just stole, er, borrowed the "1,4,7,10" - I had "*" for the month and had [[ `date +%m%a` == @(01|04|07|10)... ]] to select the month.

Thanks much for the quick response . appreciate your help derekludwig & RudiC. I will consider these examples and reading cron man page as well. I will test it on lab box. :slight_smile:

Thank you