Sometimes you want to run one cronjob command at a time. Like rsync something or any other command which could interfere the next run. Imagine cronjob runs the rsync every 5 minutes. To avoid running multiple rsyncs at same time we can use helping script which creates the lock while rsync is running and removes it when rsync is done. So the script itself is below. Adapt it to your needs. Do you have idea how it can be improved or optimized? Leave a comment!

UPD: you can add the trap to the script in case it gets killed accidentally, to remove the lockfile. Just before first if insert:

One Thought on “Simple script for any cronjob to avoid multiple instances of commands running

  1. Pingback: Sync SVN repositories with svnsync | Sysadmin notes

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post Navigation