-2

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" ?

JAN
  • 21,236
  • 66
  • 181
  • 318
  • Instead of killing the first cronjob with the second, why don't you make the add-prod.sh kill itself after 10 seconds. See https://stackoverflow.com/questions/5161193/how-to-kill-a-child-process-after-a-given-timeout-in-bash – Dylan Reimerink Nov 04 '21 at 17:58

1 Answers1

-1

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.

b2f
  • 196
  • 2
  • 10