0

I need to change the below schedule to exclude Tuesday and Thursday for only the 2nd hour.

0 2,20 * * *

I want to run a job everyday at 2 am and 8pm, but on Tuesdays and Thursdays exclude the 2 am job.

  • lazy way: 2 cron jobs? See https://stackoverflow.com/questions/16717930/how-to-run-crontab-job-every-week-on-sunday – Dave S Jun 06 '19 at 20:54

2 Answers2

0

I think all you need is

0 2,20 * * 1,3,4,6,7

the numbers at the end are the days of the week. O being Sunday.

  • Sunday is either zero or seven; monday through saturday is always 1-6. Read the cron docs : "day of week 0-7 (0 or 7 is Sunday, or use names)" – parttimeturtle Jun 06 '19 at 21:34
0

The easiest answer is going to be two separate entries in your crontab:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

 * 2,20 *  *  0,1,3,5,6 root /path/to/command.sh
 *  20  *  *  2,4       root /path/to/command.sh

Make sure that command.sh isn't in an /etc/cron.* folder.

parttimeturtle
  • 1,125
  • 7
  • 22