2

I use the node-cron npm package to run a job that should execute only ONCE every 5 minutes However , the output i get is that the job executes continously till the entire minute is complete,it executes more than once.

cron.schedule('*/5 * * * *', () => {
           console.log('running a task once every 5th minute');
         });

Output:

running a task once every 5th minute
running a task once every 5th minute
running a task once every 5th minute
running a task once every 5th minute

1 Answers1

0

. Execute a cron job every 5 Minutes The first field is for Minutes. If you specify * in this field, it runs every minutes. If you specify */5 in the 1st field, it runs every 5 minutes as shown below.

*/5 * * * * /home/User/backup.sh

Note: In the same way, use */10 for every 10 minutes, */15 for every 15 minutes, */30 for every 30 minutes, etc.

  1. Execute a cron job every 5 Hours The second field is for hours. If you specify * in this field, it runs every hour. If you specify */5 in the 2nd field, it runs every 5 hours as shown below.

    0 */5 * * * /home/User/backup.sh
    

It will surely run for 5 hours only.

Rewrite it and then run.

KJA
  • 85
  • 5