Don't make it cron's responsibility to check whether the script isOn Thursday, 23.04.2009 at 13:42 +0530, Kurian Thayil wrote:
> I have 3 cron jobs enabled and all are relating to RSYNC. Now, all of these
> scripts are run once in every 7 minutes all day. The problem occurs when the
> scripts doesn't finish to execute in 7 minutes. This will result in starting
> execution of the same script again and this will malfunction the setup.
>
> Is there an option in CRON, which always check if CRON has started the
> process and is already running? Cron should execute the script only if the
> the process isn't running already. Any hints on this?
already running. Make it the *scripts's* responsibility.
For example, the script should create a marker file (or similar) when it
runs, deleting the marker file upon completion. The *first* thing the
script should do is check for the existence of the marker file and, if
it exists, then another instance of the script is already running; you
can then terminate the script at that point.
e.g. (partly bash, partly pseudo-code, completely untested)
MARKER=/home/username/tmp/marker.txt
if [ -e $MARKER ]; then
echo Script already running
exit
touch $MARKER
[...]
[... real script here ...]
[...]
rm $MARKER
Dave.
--
Dave Ewart
davee@ceu.ox.ac.uk
Computing Manager, Cancer Epidemiology Unit
University of Oxford / Cancer Research UK
PGP: CC70 1883 BD92 E665 B840 118B 6E94 2CFD 694D E370
Get key from http://www.ceu.ox.ac.uk/~davee/davee-ceu-ox-ac-uk.asc
N 51.7516, W 1.2152
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iD8DBQFJ8CbpbpQs/WlN43ARAkHRAJ9Jn+w/m3JpIPFn131OVVVkgmKYOACglczD
MqzsbR6QH9Es1WsoUAZhTCk=
=iHhR
-----END PGP SIGNATURE-----