How to run Cron job every 5 days

cron

I have 5 shell scripts, I want to run them in 5 days cycle, like follows:

Day 1 : script 1
Day 2 : script 2
Day 3 : script 3
Day 4 : script 4
Day 5 : script 5

Day 6 : script 1
Day 7 : script 2
Day 8 : script 3
Day 9 : script 4
Day 10 : script 5

And keep the scripts runing in 5 day cycle. How can I set it in cron jobs?

Thanks

Best Answer

cron by itself doesn't support this. The eariest way to accomplish what you want is probably to ask cron to execute a dispatcher script every day (at the same time) and have the dispatcher script decide which other script to run based on what day it is. For example:

#!/bin/sh

case $(expr $(date +%s) / 86400 % 5) in
   0)
       exec /script/for/day/1
       ;;
   1)
       exec /script/for/day/2
       ;;
   2)
       exec /script/for/day/3
       ;;
   3)
       exec /script/for/day/4
       ;;
   4)
       exec /script/for/day/5
       ;;
esac
Related Question