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

SexyMF
  • 209
  • 1
  • 2
  • 10
  • 1
    possible duplicate of [How to schedule server jobs more intelligently than with cron?](http://serverfault.com/questions/376717/how-to-schedule-server-jobs-more-intelligently-than-with-cron) – user9517 Apr 30 '14 at 16:08

3 Answers3

12

Use flock.

flock -n /path/to/lockfile -c "command_you_want_to_run"
sciurus
  • 12,493
  • 2
  • 30
  • 49
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

Ressu
  • 246
  • 1
  • 5
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.

mdpc
  • 11,698
  • 28
  • 51
  • 65