0

I'm wondering, if I set a cronjob for every two days, which two days will they be? Would it be today and then the day after tomorrow? Or tomorrow and then 2 days after that?

Say it was noon on Monday and I set the job to run every 2 days at 5pm. Would the first time it ran be this afternoon or 29 hours from now?

  • 2
    Please edit your question to show the line in crontab for the job, and we can answer your question. Otherwise we can only guess. – sudodus Jan 25 at 5:45
3

If you used */2 in some field, looking at man 5 crontab:

The time and date fields are:

      field          allowed values
      -----          --------------
      minute         0-59
      hour           0-23
      day of month   1-31
      month          1-12 (or names, see below)
      day of week    0-7 (0 or 7 is Sun, or use names)

A field may be an asterisk (*), which always stands for ``first-last''.

And:

Step  values can be used in conjunction with ranges.  Following a range with ``/<number>''
specifies skips of the number's value through the range.  For example, ``0-23/2''  can  be
used  in the hours field to specify command execution every other hour (the alternative in
the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). 

So */2 for day of month is 1, 3, ... and for day of week is 0, 2, ....

If you used the day of week field (going by the mention of Monday), then it would first run on Tuesday (since 0 is Sunday, 2 is Tuesday). If you used the day of month field, it would run on Monday if the date on Monday was an odd number, and on Tuesday otherwise.

  • That's exactly what I was looking for. Thanks for taking the time! – jaret217 Jan 26 at 5:32

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.