Cron Question
RW
fbsd06 at mlists.homeunix.com
Tue Sep 2 17:50:39 UTC 2008
On Tue, 2 Sep 2008 11:40:37 -0500
Dan Nelson <dnelson at allantgroup.com> wrote:
> I use the lockfile command ( from the procmail port ) to ensure that
> recurring cron jobs don't overlap if one run takes too long. For
> example, to run mrtg on a 1-minute cycle but prevent multiple mrtgs
> from running if one run takes longer than 1 minute:
>
> * * * * * /usr/local/bin/lockfile -r 1 -l 3600 /tmp/mrtg.LCK &&
> ( nice -19 /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg ;
> rm /tmp/mrtg.LCK )
>
> The -l 3600 tells lockfile to remove any lockfiles over an hour old (
> if the machine was rebooted during an mrtg run for example )
>
you could also handle stale lock-files, without installing procmail,
like this:
LCK=/tmp/foo.LCK
find $LCK -mtime +3600s -delete
if ![ -f "$LCK" ] ; then
touch "$LCK"
[ -f "$LCK" ] && foo
rm "$LCK"
fi
Presumably the lockfile command also eliminates the race between testing
for, and creating, the lock-file, but that's not really needed here.
More information about the freebsd-questions
mailing list