Re: Cron Timing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 20Apr2010 09:34, Steven Barre <steven@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
| I know that you can get cron to do something "every x". For example
| to have something run every 15 min you would do
| 
| */15  *  *  *  * php /path/to/script.php
| 
| But now I have a whole bunch of these set up and having them all run
| at exactly the same time is causing issues.
| 
| Is there any way to stagger these? Like tell it to run every 15 min
| + 2 min so it runs at 02, 17, 32, and 47 minutes past the hour?
| 
| Or is my best bet to simply put a sleep at the start of the script
| with a random time?

Leaving aside the other suggestions to simply write staggered times,
some other "automatic" approaches are available.

1: Put all the jobs in one shell script:
    
    #!/bin/sh
    php /path/to/script1.php
    php /path/to/script2.php
    ... etc ...

  and have in cron:

   */15  *  *  *  * /path/to/the-above-wrapper-script

  which will run them in sequence.
  Of course that relies on the all having exactly the same timing.

2: Use a locking system:

    */15 * * * * with_lock "lock_name" php /path/to/script1.php
    */15 * * * * with_lock "lock_name" php /path/to/script2.php

   which prevents any of them running at the same time.  with_lock is a
   script you must write, to obtain a lock of some kind, run the command, and
   release the lock. That way when two jobs coincide, one will wait for the
   other to complete before proceeding.

   I use this script:
     http://www.cskk.ezoshosting.com/cs//css/bin/lock
   for this purpose.


-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Wooflechogs: creatures that live in the Patagonian mountains which resemble
sheep but have the two legs on one side longer than the other two legs so
they can stand upright on the sides of the steep mountains.  These creatures
have steel wool instead of normal stuff, and every spring the helicopters fly
in, pick them up with large magnets, and fly them back to the flat ground,
where they run around in ever diminishing circles until they get to the
middle, where the shearing shed is, and where they are shorn to make Steelo
soap pads.
        - Jens Kieffer-Olsen <Comp2002@xxxxxxxxxxxxxxxx>

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux