I've searched for this but cant seem to find an answer. I was reading the following post Cron Job for Every 3 days which is almost what i need:
The command for “day of the year” is
date +%-j
Where the hyphen before the “j” means “don’t pad” (with zeros in this case – so we can use it as a number). Now we just check if this is evenly divisible by three by using the modulo – % – which returns the remainder of dividing.
$(( 'date +%-j' % 3 ))
The $(( )) part tells bash to perform a calculation, and the backticks are there to run our date command separately from the rest. So if this calculation is zero, we have a winner.
[ $(( 'date +%-j' % 3 )) == 0 ]
Remember, though, we need an offset so that we start on the 1st. The way it is currently, it starts on the 3rd. Just by subtracting one from the day of the year, we can get everything to line up. We have to wrap that calculation with $(( )) as well.
[ $(( $(( 'date +%-j' - 1 )) % 3 )) == 0 ]
That test fulfills our conditions so our full crontab entry would be:
30 05 * * * [ $(( $(( 'date +%-j' - 1 )) % 3 )) == 0 ] && execute_this
However i have a specific case to run this every 2.5 days. Is this not at all possible in cron? Is it a matter of switching the 3 our for 2.5 or not?
i know i can do 2 and a half hours by specifying minutes instead, but 2.5 days?
For information I'm using the Whenever Gem in a Ruby on Rails application, but may have to edit cron manually.
Any advice here is greatly appreciated.