From owner-freebsd-questions@FreeBSD.ORG Mon Sep 16 12:05:22 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0F0EBB86 for ; Mon, 16 Sep 2013 12:05:22 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C83C527CF for ; Mon, 16 Sep 2013 12:05:21 +0000 (UTC) Received: from r56.edvax.de (port-92-195-74-65.dynamic.qsc.de [92.195.74.65]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 96F1E3DB23; Mon, 16 Sep 2013 14:05:12 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r8GC542R005599; Mon, 16 Sep 2013 14:05:04 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Mon, 16 Sep 2013 14:05:04 +0200 From: Polytropon To: Paul Macdonald Subject: Re: test if script called by cron Message-Id: <20130916140504.739fd28f.freebsd@edvax.de> In-Reply-To: <5236EB03.7040001@ifdnrg.com> References: <5236EB03.7040001@ifdnrg.com> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Sep 2013 12:05:22 -0000 On Mon, 16 Sep 2013 12:26:59 +0100, Paul Macdonald wrote: > Is there a simple way of testing whether a given script was called via cron, > > I'd rather find a solution that would work from within the script rather > than setting an environment variable in the crontab. I'd suggest the script creates a file (lock file or, much easier, just a simple normal file) at its beginning: #!/bin/sh /usr/bin/touch /tmp/scriptrun # ... your script content here ... You could also output the date command to that file to see when the script has been called: #!/bin/sh /bin/date "+%Y-%m-%d %H:%M:%S" > /tmp/scriptrun # ... your script content here ... Of course you would have to manually remove that file after you have verified its existence and content. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...