Date: Mon, 16 Sep 2013 14:05:04 +0200 From: Polytropon <freebsd@edvax.de> To: Paul Macdonald <paul@ifdnrg.com> Cc: freebsd-questions@freebsd.org 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>
next in thread | previous in thread | raw e-mail | index | archive | help
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, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130916140504.739fd28f.freebsd>