Date: Tue, 2 Sep 2008 18:50:33 +0100 From: RW <fbsd06@mlists.homeunix.com> To: freebsd-questions@freebsd.org Subject: Re: Cron Question Message-ID: <20080902185033.523d001f@gumby.homeunix.com.> In-Reply-To: <20080902164037.GM26653@dan.emsphone.com> References: <19272656.post@talk.nabble.com> <20080902160351.GI79391@pcjas.obspm.fr> <D59C3198F12C06340437288A@Macintosh.local> <20080902164037.GM26653@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2 Sep 2008 11:40:37 -0500
Dan Nelson <dnelson@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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080902185033.523d001f>
