72

Hi I want to create a cron expression excluding saturday and sunday.

7
  • 3
    Did you read the crontab(5) man page e.g. linux.die.net/man/5/crontab ? Feb 4, 2012 at 19:50
  • 6
    I really don't see why this question 'is not on topic'.
    – carla
    Jul 18, 2016 at 13:48
  • 3
    This is off topic because it has nothing to do with programming in the normal definition, but is more related to server administration. Therefore, serverfault.com is the proper place for this question (even if it's for a workstation crontab settings are still most often used on servers). One could loosely say it is programming the computer, but it's not programming as most people would define it.
    – J Roysdon
    Aug 21, 2020 at 0:44
  • @JRoysdon thank goodness for your explanation. It can be very difficult on this site to deal with open-loop feedback, where something is deemed bad, but you have very little idea why it was deemed bad and therefore are unsure how to prevent a similar mistake in the future. In your case, you closed the loop with the feedback and it can be a good signal to future posters where the lines are between programming-specific and otherwise more computer-related questions not specific to programming, as well as where the more appropriate place to post is. Again, thank you. Aug 26, 2020 at 4:42
  • @MichaelPlautz JRoysdon Your are both joking right ? Of course cron expression are about programming, just like regexp. You can't use CronTriggers from Quartz framework without knowledge about cron expressions : quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/… I vote for reopen an obviously useful question.
    – Tristan
    Jan 14, 2022 at 10:11

3 Answers 3

139

Begin the line with 0 0 * * 1,2,3,4,5 <user> <command>. The first fields are minutes and hours. In this case the command will run at midnight. The stars mean: for every day of the month, and for every month. The 1 to 5 specify the days. monday to friday. 6=saturday 0=sunday.

3
26

Try this:

# run every two hours at the top of the hour Monday through Friday
0 */2 * * mon-fri <command>
3
  • 3
    "Use the first three letters of the particular day or month (case doesn't matter). Ranges or lists of names are not allowed."
    – scribu
    Dec 14, 2014 at 16:01
  • 5
    @scribu I guess it's relative to the cron daemon you use. In my case dcron which Slackware ships with does support this feature, it's even one of their examples.
    – SiegeX
    Dec 15, 2014 at 16:39
  • crontab.guru/#*/10___*_1,2,3,4,5 it is very easy: “At every 10th minute on Monday, Tuesday, Wednesday, Thursday, and Friday.”
    – Bitdom8
    May 7, 2022 at 11:08
-1

To sum it up simples, 0 represents Sunday and 6 Saturday:

  • */10 * * * 1-5 - At every 10th minute on very day-of-week from Monday through Friday.
  • */10 * * * 0,6 - At every 10th minute on Sunday and Saturday.

Not the answer you're looking for? Browse other questions tagged or ask your own question.