56

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

gWaldo
  • 11,957
  • 8
  • 42
  • 69
haim evgi
  • 753
  • 1
  • 10
  • 15

4 Answers4

98

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.

Richard Holloway
  • 7,456
  • 2
  • 25
  • 30
  • 5
    +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 06 '10 at 14:27
  • 11
    wouldn't `*/3` be every four months (12/3 = 4)? – warren Feb 29 '16 at 21:45
  • 9
    @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
  • 4
    @warren it really should be a mod operator rather than a division. But oh well ¯\_(ツ)_/¯ – Goahnary Dec 28 '16 at 19:17
  • @Goahnary So I think it will run on Mar, Jun, Sep, & Dec right rather than in answer: 'Jan,Apr,Jul,Oct' – bharat Jun 04 '19 at 05:09
8

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
David Spillett
  • 22,754
  • 45
  • 67
Jon Rhoades
  • 4,987
  • 3
  • 31
  • 48
3

The accepted answer is good, thou I'd use an alternative with simpler numbers and easier to read: https://crontab.guru

0 0 1 */3 *

Read like this: “At 00:00 on day-of-month 1 in every 3rd month.”

0

For JIRA (and other 6 digit cron expressions):

0 0 0 1 JAN,APR,JUL,OCT ?

lobi
  • 1,083
  • 2
  • 15
  • 30