LT21j
LT21j

Reputation: 175

Clean way to run a cron after a certain time on Sunday and before a time on friday

I am looking for a way to run a script every two hours starting after a 1pm on Sunday and ending at 1pm on Friday.

Is there any special cron job syntax for this? The only way I can think of to do it this is something like:

00 */2 * * 0-5 [ [ `/bin/date +\%u` -eq 0 ] && [ `/bin/date +\%H` -gt 13 ] || \
                 [ `/bin/date +\%u` -eq 5 ] && [ `/bin/date +\%H` -lt 13 ] ] && /run_script.sh

Which feels kind of dirty...Is there any better way to do this?

Upvotes: 0

Views: 66

Answers (1)

inverzeio
inverzeio

Reputation: 555

0 13-23/2 * * 7 /run_script.sh
0 1-23/2 * * 1-4 /run_script.sh
0 1-13/2 * * 5 /run_script.sh

3 entries seems easier for the eye?

Upvotes: 2

Related Questions