简体   繁体   中英

Run Cron Job every 5 minutes for 10 seconds

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

You could do this with sleep function. Something like:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM