7

I want to run a cron every 5 minutes, but I don't want the next cron to run if the previous did not finish yet.

What can be done about this? Are there any tools to support this?

Thanks

1

3 Answers 3

12

Use flock.

flock -n /path/to/lockfile -c "command_you_want_to_run"
2
  • 1. will the file be released after command_you_want_to_run? 2. how can that be integrated with a cron? ****5 flock -n .... is that right? Thanks
    – SexyMF
    Apr 29, 2014 at 19:15
  • 1: Yes. 2: Yes.
    – sciurus
    Apr 29, 2014 at 19:25
5

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

4

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.

Not the answer you're looking for? Browse other questions tagged .