用于停止Cron作业重叠的代码 [英] Code for stopping the overlapping of the Cron job
本文介绍了用于停止Cron作业重叠的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要停止cron作业的重叠,例如:如果cron作业被安排在早上2时钟为DB备份和其他cron作业被安排在早上7时钟为DB备份再次。我需要停止如果2 o时钟的数据库备份未完成,则7时钟计划cron作业。
I need to stop the overlapping of cron jobs for example:If a cron job is scheduled at morning 2 o clock for DB backup and other cron job is scheduled at morning 7 o clock for DB backup again.So i need to stop the 7 o clock scheduled cron job if the DB backup for 2 o clock is not completed.
推荐答案
这是鸡群的用途。从 man flock
:
...
The third form is convenient inside shell scripts, and is usually used
the following manner:
(
flock -n 9 || exit 1
# ... commands executed under lock ...
) 9>/var/lock/mylockfile
...
$ b b
在这种情况下,flock会尝试在fd 9上为 / var / lock / myfile
获得一个锁。如果它不能(因为早期的作业仍在运行),它将退出。
In this case, flock will try to get a lock on fd 9 for /var/lock/myfile
. If it can't (because the earlier job is still running), it will exit.
您需要将它放在脚本中。
You need to put it in a script.
这篇关于用于停止Cron作业重叠的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文