From owner-freebsd-questions@FreeBSD.ORG Tue Sep 2 17:50:39 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D287C1065674 for ; Tue, 2 Sep 2008 17:50:39 +0000 (UTC) (envelope-from fbsd06+ZM=07d23d09@mlists.homeunix.com) Received: from mxout-03.mxes.net (mxout-03.mxes.net [216.86.168.178]) by mx1.freebsd.org (Postfix) with ESMTP id AAAD28FC1F for ; Tue, 2 Sep 2008 17:50:39 +0000 (UTC) (envelope-from fbsd06+ZM=07d23d09@mlists.homeunix.com) Received: from gumby.homeunix.com. (unknown [87.81.140.128]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTP id 9CCC223E49B for ; Tue, 2 Sep 2008 13:50:37 -0400 (EDT) Date: Tue, 2 Sep 2008 18:50:33 +0100 From: RW To: freebsd-questions@freebsd.org 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> <20080902164037.GM26653@dan.emsphone.com> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.11; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: Cron Question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Sep 2008 17:50:39 -0000 On Tue, 2 Sep 2008 11:40:37 -0500 Dan Nelson 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.