Home > Software design >  Run Cron Job every 5 minutes for 10 seconds
Run Cron Job every 5 minutes for 10 seconds

Time:11-05

I have a script that I want to run every 5 minutes for 10 seconds.

*/5 * * * * /root/XXX/cronjobs/add-prod.sh

It seems logical to have another cron job that would run every 5 minutes and 10 seconds that would turn off the 1st cron job.

Something like this:

[FORMULA HERE] /root/XXX/cronjobs/rem-prod.sh

How can we set a formula for "every 5 minutes and 10 seconds" ?

CodePudding user response:

You can do this via timeout. It will kill the process after 10 seconds. It would be better than killing the process externally. Otherwise, jakob22's answer is the best one.

*/5 * * * * /usr/bin/timeout 10 /root/XXX/cronjobs/add-prod.sh

Edit: This is already featured in a comment.

CodePudding user response:

You could do this with sleep function. Something like:

*/5 * * * * sleep 10;/root/XXX/cronjobs/rem-prod.sh

  • Related