0

I want to do this:

Execute Task A today 6:00am, and then every two days after that.

Execute Task B tomorrow 6:00am, and every two days after that.

TimP
  • 210
  • 2
  • 11
Yifan Wang
  • 504
  • 6
  • 13

2 Answers2

0

The normal solution for having a cron job execute every two days would be using */2 in the days field, but that doesn't support alternating days.

You'd probably have to make a list of days:

0 6 */2 * * #Job to execute every even numbered day
0 6 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * #Job to execute every odd numbered day

Note that this won't be perfect on months that end with an odd number of days. Since it will end up executing the second job twice in a row, on the 31st and the 1st.

It's probably worth looking at man crontab on your system as well. Some crons support more complex forms of scheduling, such as dependencies (wait until this job finishes, then wait another X hours and run this other job) which could be useful to you.

TimP
  • 210
  • 2
  • 11
0

You could use date %s to determine if it is an "odd" day or "even" day in a running calendar free of manmade boundaries of years and months. For example:

$ [ $(( `date +%s` / 86400 % 2 )) -eq 0 ] && echo A || echo B

And drive Task A or Task B thus.

Dinesh
  • 4,437
  • 5
  • 40
  • 77