Cron overlaping

133 views
Skip to first unread message

ismailctest C

unread,
Mar 22, 2023, 3:01:50 AM3/22/23
to Wazuh mailing list
Hi Team,
How to avoid cron overlapping.

Eg: Scheduled a cron every 5 minutes to upload files & some times it is taking more than 5 minutes to complete it. If its not completed the current cron, should not start the cron again.

How to do this? Can anyone can help with any script with details.


Himanshu Sharma

unread,
Mar 22, 2023, 4:30:59 AM3/22/23
to Wazuh mailing list
Hi ismailctest C,Can you please update us with more details about your issue? Like what cron job command you are using, and which files you are trying to upload.If you are trying to avoid cron overlapping on a Linux system then there are several methods.
you can use the flock command like below.
crontab -l \* \* \* \* \* flock -w 0 /path/to/cron.sh
If flock does not yet exist on your system, you can install it using the following commands
 yum install util-linux or
apt-get install flock, depending on your Linux Distribution
 you can follow the below documentation for more details:https://ma.ttias.be/prevent-cronjobs-from-overlapping-in-linux/Hope this information helps you. Please feel free to reach out to us for any information/issues.

ismailctest C

unread,
Mar 22, 2023, 5:12:29 AM3/22/23
to Wazuh mailing list
Hi Himanshu,
Thanks a lot.

The below cron is using which is downloading logs from one of the device.
*/5 * * * * /usr/bin/python3 /var/log/remote/new/abc_script.py

Could you please share the other methods also.
The above cron is running every 5 minutes to download logs, normally completing it with in 2 minutes, sometimes it is taking more than 5 minutes.
Before starting the next cron, should be checked the previous task is completed or not, if not completed, skip the cron and wait for next 5 minutes.
Everytime needs to check the same.

Aditya Sharma

unread,
Mar 24, 2023, 6:41:37 AM3/24/23
to Wazuh mailing list
Hi ismailctest C,For another method, without using lock files, you can use the pgrep command as the following documentation.https://ma.ttias.be/prevent-cronjobs-from-overlapping-in-linux/And you can also increase the cronjob time also if it's happening frequently.Hope this information helps you.
Reply all
Reply to author
Forward
0 new messages