2

I have data coming from API and I want to call it and dump the data in my db every 4 hours (current day data). I used the following :

0   */4 *   *   *

The data in my report is missing some values, I was thinking that the cronjob is called like this :

today       00:00:00  -> should return nothing for today results
today       04:00:00  -> should return data for today
              ....
today       20:00:00  -> should return data for today
tomorrow    24:00:00  -> should return data for today, but this is tomorrow !

So I am thinking now of calling it like this :

today       00:00:00  -> should return nothing for today results
today       03:59:59  -> should return data for today
              ....
today       19:59:59  -> should return data for today
tomorrow    23:59:59  -> should return data for today, but this is tomorrow !

I am not able to achieve this cronjob. Or there is a better way ?

schaiba
  • 7,493
  • 1
  • 33
  • 31

2 Answers2

1

Seconds and negative time are not possible in crontab. Simply wait 59 seconds in the 59th minute of the previous hour. Example crontab:

#
# minute  0-59
# hour    0-23
# dom     1-31
# mon     1-12 (or names)
# dow     0-7  (0 or 7 is Sun, or use names)
#
59 23,3,7,11,15,19 * * * sleep 59 && /bin/datadump
ingopingo
  • 807
  • 5
  • 7
0

Unfortunately cron is designed to be more pattern recognition than arithmetic, so something like -1 0 /4 * * * won't work. You can just specify each hour manually with the comma, so this should hopefully have the desired result:

59 59 3,7,11,15,19,23 * * *

Running a second before the hour is a little too trusting of your database, though. I'd personally give it a few more seconds' grace to wrap up (else it'll still dump tomorrow's data).