Cron job time syntax

270 Views Asked by At

I have a cron job that processes an action for several records in my database. I want it to process each record with a 5 minute delay, then repeat the process every 12 hours. What is the syntax that I need to use to make this happen? For example, if I have 5 rows in my database that the cron job will process. I want it to process the first row, then process the next row 5 minutes later, then process the next row 5 minutes later, etc. until all rows have been processed. Then repeat the whole process every 12 hours. I tried using */5 */12 * * * but it did not work.

1

There are 1 best solutions below

4
On

It won't work the way you have configured.

if I have 5 rows in my database that the cron job will process. I want it to process the first row, then process the next row 5 minutes later, then process the next row 5 minutes later, etc

Write a shell scrip to achieve above goal. Cron won't do it for you. Hint: use sleep function in your scrip to wait for 5 minutes before processing next record.

Then repeat the whole process every 12 hours

use * */12 * * * in cron to let your shell script run after every 12 hrs.

So, in short, Cron will trigger a run of you script very 12 hrs AND your script has the logic to wait for 5 minutes between processing any two consecutive DB records.