10

In order to run cron in the night at 4am, do I need to write 4 * * * *?

And to run at 4pm o'clock, should it be 16 * * * *?

  • Since Google is still serving up this topic, new visitors might like to know about www.cronsandbox.com where you can experiment with the different timing values and see a schedule. – Art Stanmore Jan 9 '16 at 17:47
  • Unfortunately, it appears www.cronsandbox.com is no more. – Jordan May 5 '17 at 1:33
13

No. This would run at the 4th and 16th minute of every hour.

You're looking for:

0 4,16 * * * command

That will run at both 4am and 4pm.

Or if the two commands are different:

0 4 * * * command
0 16 * * * another_command
  1. The first column sets the minutes. In these examples, I'm setting it at 0 so the event happens on the hour.

  2. The in the next column we set the hour you want it to run. We use absolute values but you can use */2 for "every other hour", etc.

  3. The next column says that we want this to happen every day of the month.

  4. The next column denotes the months that this should trigger on (all in this case).

  5. The last column says which days of the week this is allowed to trigger on. 0-7 (where both 0 and 7 are Sunday). * means it can trigger on any day of the week.

0

No, that's not correct. The meaning of the fields

* * * * *

for each asterisk slot respectively:

  • minute (0 - 59)
  • hour (0 - 23)
  • day of month (1 - 31)
  • month (1 - 12)
  • day of week (0 - 6) (Sunday=0 or 7)

So for everyday 4am and 4pm you should use:

0 4,16 * * *

If you leave a slot just as * it will mean every iteration of that time unit i.e. every hour, daily etc.

Here, the part 0 4,16 means it will run at 0 minute of 4am and 4pm (i.e 4:00am and 4:00pm). If you wanted to run it at, let's say 15 minutes of 4am and 4pm instead you would change it to 15 4,16 * * * (i.e. 4:15am and 4:15pm).

  • 8
    Not correct. This would run at every minute during 4am and 4pm. eg: 04:00, 04:01, 04:02, etc – Oli Jan 7 '11 at 15:36
  • This answer should be deleted. This is now a Famous Question and we do not want people spamming up this question with incorrect answers. – fosslinux Aug 4 '16 at 2:40
  • @Oli The answer has just been corrected. – Melebius Sep 18 '18 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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