32

What would be the crontab entry look like for a job that runs on the first day of every third month?

67

The following will run script on the 1st of Jan, Apr, Jul and Oct at 03:30

30 03 01 Jan,Apr,Jul,Oct * /path/to/script

Alternatively, but less obvious

30 03 01 */3 * /path/to/script

Will run every three months at 03:30 on the 1st of Jan,Apr,Jul and Oct.

  • 4
    +1: I always thought the / notation was the MOST obvious...I use it wherever possible. (Words in the scheduling part of the crontab freak me out...I'd do: "0 0 1 3,6,9,12 * /path/to/script.bash" if I couldn't do /3) – Satanicpuppy Apr 6 '10 at 14:27
  • 10
    wouldn't */3 be every four months (12/3 = 4)? – warren Feb 29 '16 at 21:45
  • 7
    @warren No it would not. The logic here is more of a mod truth statement. Ex: if(12%3 == 0): run_script(). I thought about this as well! Great question. – Goahnary Dec 28 '16 at 19:13
  • 1
    @Goahnary I realized that a while after I asked for the clarification, too :) – warren Dec 28 '16 at 19:15
  • 2
    @warren it really should be a mod operator rather than a division. But oh well ¯_(ツ)_/¯ – Goahnary Dec 28 '16 at 19:17
7

Wikipedia has a nice explanation about how to configure Cron.

For your specific case you could run a Cron Expression to run every 3 months- obviously change the months to suit your schedule.

0 0 1 JAN,APR,JUL,OCT  * /path/to/script.bash
  • 2
    -1 Whilst this has been marked correct answer, it will error as the fields are in the wrong order and even if they were in the correct order would run every day at midnight through Jan, Apr, Jul, Oct (eg 01/01 02/01 ... 31/01 01/04 ..) and not just once every three months. My answer would work but was not accepted. Sad me! – Richard Holloway Apr 6 '10 at 6:36
  • @Richard Holloway - the mysteries of server fault - have updated my answer thanks for pointing out the typo – Jon Rhoades Apr 6 '10 at 6:55
  • 1
    I have removed my -1 to reflect the change. – Richard Holloway Apr 6 '10 at 7:46
  • You also shouldn't have the spaces after the commas, many cron implementations will see them as separators. You may come across implementations that demand numeric months too, though I think this is rare these days. – David Spillett Apr 6 '10 at 10:39
  • @David Spillett thanks we will get there in the end... Possibly my crapest answer ever. If I had any decency I would delete it;) – Jon Rhoades Apr 6 '10 at 11:26

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.