iSun
iSun

Reputation: 1754

Run cron job every 2 days on specified hour

How can I run a cronjob for every 2 days on a specified hour like 4:10 AM?

Is the following expression right?

10 04 * * */2 MY-COMMAND

Upvotes: 1

Views: 2199

Answers (2)

flipper
flipper

Reputation: 146

If you look at the job execution days you can find that it also depends on the month that you are using (ex) if you are trying to execute every 5 day then the job will be start and it will try to split the month in equal halfs (which is not) and thus it wont work as expected seeClick Here to check so it becomes mandatory to use the withIntervalInHours(intervalInHours) to get our case working

Upvotes: 0

tripleee
tripleee

Reputation: 189487

No, you are running on days of the week which are evenly divisible by two. So you are running it on Sun, Tue, Thu, Sat; Sun, Tue, ... (This field is zero-based.)

If you move the */2 to the month field instead (fourth field), you get the same problem with uneven periodicity in months with an uneven number of days, but the aberrant days will happen only seven times a year (eight in leap years) instead of every week.

If you absolutely require the job to run every other day, you need some kind of external logic. Maybe make the script check a run file, and abort if it's less than 25 hours old (or maybe 26 if you change the system time for daylight saving time) and otherwise proceed and update the time stamp of the run file.

Upvotes: 1

Related Questions