I doubt an interval in minutes that is not a divisor of 60 works as expected. Anyway, it is worth to try and find out.
Another solution is a bit more tricky and it requires a check at the beginning of the script. First we consider at which time the script should run: suppose it starts at midnight of a certain day, then by adding 1h and 48m progressively we get:
Code:
0:00 1:48 3:36 5:24 7:12 9:00 10:48 12:36 14:24 16:12
18:00 19:48 21:36 23:24 1:12 3:00 4:48 6:36 8:24 10:12
12:00 13:48 15:36 17:24 19:12 21:00 22:48 0:36 2:24 4:12
6:00 7:48 9:36 11:24 13:12 15:00 16:48 18:36 20:24 22:12
0:00
that is after three days the script would run at midnight again. Furthermore, as you can notice, the script would run always at minutes 0, 12, 24, 36, 48 so that the crontab entry can be
Code:
0,12,24,36,48 * * * * /my/command
Now in the script we have to be sure that the code will be executed only at 0:00, 1:48, 3:36, ... of the first day, at 1:12, 3:00, 4:48, ... of the second day and at 0:36, 2:24, 4:12, ... of the third day. And so on for every three-days period.
To do this we have to define a
reference date as the date of the first day at midnight at which we want to start our count of three-days periods. Let it be for example midnight of 8-May-2010. All the calculations are processed in seconds and... here we go:
Code:
#!/bin/bash
#
# Set the reference time
#
reftime=$(date -u -d 20100508 +%s)
#
# Compute the current time in seconds since epoch.
#
# The inner date command is to take in account the lag of 1
# or more seconds between the time specified in crontab and
# the actual time of execution. In practice remove seconds
# from the current time.
#
date=$(date -u -d "$(date -u +"%Y%m%d %H:%M")" +%s)
#
# Retrieve hour and minutes in HHMM format
#
hm=$(date -u -d @$date +%H%M)
#
# Initialize a counter. This will be the number of intervals
# of 108 minutes, that represents how long we are distant
# from 00:00 of the first day of the current three-days period.
#
count=0
#
# Now subtract 108 minutes from the current date progressively,
# until we reach the previous midnight. Do this for a maximum
# of 40 times (if not it might generate an infinite loop when
# we are at a certain time of the day)
#
while [ $hm -ne 0 -a $count -lt 40 ]
do
((count++))
hm=$(date -u -d @$(($date - 6480 * $count)) +%H%M)
done
#
# Compute the date in seconds since epoch at which it reached
# midnight or it went back in time for 3 days (time is not
# midnight but the number of 108-minutes intervals is 40)
#
date=$(date -u -d @$(($date - 6480 * $count)) +%s)
#
# Check now! Compute the difference between the resulting
# date and the reference time, divide by 3 days (in seconds)
# and if the remainder is 0 execute the code, otherwise do
# nothing
#
if [ $(( ($date - $reftime) % 259200 )) -eq 0 ]
then
< code here >
fi
In practice, it checks that the distance (in time) between the date computed by subtracting 108 minutes progressively and the reference time is exactly a multiple of 3.
Note that all the dates computed by the date command are in UTC time. This should avoid problems in calculations at the passage from and to Daylight Saving Time. Anyway, I'm not sure if this passage will generate some other problems (further testing needed). Hope this helps.