Crontab job dependency to prevent race [closed]

Solution 1:

Use flock.

flock -n /path/to/lockfile -c "command_you_want_to_run"

Solution 2:

You can use the run-one command. It automatically creates a lock file for the command being run.

run-one rsync -a mirror.kernel.org::everything /my/hd

The behavior is similar to flock, but the syntax is more clear. The downside is that you might need to install the command to use it. Also, special attention should be paid when modifying the command line, when the command line changes, so does the lock file name

Solution 3:

Cron does not support any type of job dependancies. The entries you put in there run when specified.

You are going to have to put in some simple interlocking scheme. Putting the given command or set of commands in a wrapper script containing the locking scheme.

Or as larger sites do, install some type of job scheduling applications and use that to run the applications with conditions.