Re: Cron - any advanced options?

2009-04-25 Thread Andrei Popescu
On Thu,23.Apr.09, 03:39:44, Dave Sherohman wrote:
 
 Depending on the script, you may also be able to accomplish this with ps
 instead:
 
 ps ax | grep [m]y-script-name

Shorter:

pgrep my-script-name

Regards,
Andrei
-- 
If you can't explain it simply, you don't understand it well enough.
(Albert Einstein)


signature.asc
Description: Digital signature


Re: Cron - any advanced options?

2009-04-25 Thread Rick Thomas
Here's a little program that I picked up I don't remember where.  It's  
what I use when I have this sort of problem.  It atomically creates a  
lock file and tests for a previous lock file of the same name --  
properly handling processes that quit without removing the lock, etc...


Rick




shlock.shar
Description: Binary data







Re: Cron - any advanced options?

2009-04-24 Thread Jeffrey Cao
On 2009-04-23, Sjoerd Hardeman sjo...@lorentz.leidenuniv.nl wrote:
 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --enig96969A47323B843026EC6D74
 Content-Type: text/plain; charset=UTF-8; format=flowed
 Content-Transfer-Encoding: quoted-printable

 Kurian Thayil wrote:
 Hi All,
 =EF=BF=BD
 I have 3 cron jobs enabled and all are relating to RSYNC. Now, all of=20
 these scripts are run once in every 7 minutes all day. The problem=20
 occurs when the scripts doesn't finish to execute in 7 minutes. This=20
 will result in starting execution of the same script again and this wil=
 l=20
 malfunction the setup.
=20
 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?
 You could create a lockfile
touch /var/lock/cronfiletest
 and the test if this lockfile exists, or else exit
test -f /var/lock/cronfiletest || exit 0
Should it be this?
test -f /var/lock/cronfiletest  exit 0
if you want to exit when the lock file exist.

 You'll find similar tricks in many cron and init scripts.

 Sjoerd

 PS. Kurian, my apologies for the message sent to you. Hit the 'reply'=20
 vs. 'reply to list' button accidentally.


 --enig96969A47323B843026EC6D74
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename=signature.asc


 --enig96969A47323B843026EC6D74--




-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Cron - any advanced options?

2009-04-24 Thread Sjoerd Hardeman

Jeffrey Cao wrote:

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?

You could create a lockfile
   touch /var/lock/cronfiletest
and the test if this lockfile exists, or else exit
   test -f /var/lock/cronfiletest || exit 0

Should it be this?
test -f /var/lock/cronfiletest  exit 0
if you want to exit when the lock file exist.

Yes, of course. You're absolutely right.

Sjoerd



signature.asc
Description: OpenPGP digital signature


Cron - any advanced options?

2009-04-23 Thread Kurian Thayil
Hi All,

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?

Regards,

Kurian Thayil.


Re: Cron - any advanced options?

2009-04-23 Thread Dave Ewart
On 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?

Don't make it cron's responsibility to check whether the script is
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
da...@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


signature.asc
Description: Digital signature


Re: Cron - any advanced options?

2009-04-23 Thread Kurian Thayil
Hi,

Thats a pretty good idea. But I was thinking of an option like the one in
Fcron. Fcron doesn't allow to start the process if it's already running
(started by fcron). So I guess there should be a similar option in crontab
too.

Regards,

Kurian Thayil

On Thu, Apr 23, 2009 at 1:59 PM, Dave Ewart da...@ceu.ox.ac.uk wrote:

  On 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?

 Don't make it cron's responsibility to check whether the script is
 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
 da...@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-




Re: Cron - any advanced options?

2009-04-23 Thread Dave Sherohman
On Thu, Apr 23, 2009 at 09:29:29AM +0100, Dave Ewart wrote:
 Don't make it cron's responsibility to check whether the script is
 already running.  Make it the *scripts's* responsibility.

Agreed.  If you make cron responsible for making sure it doesn't run
twice, what happens when someone decides they should (for whatever
reason) run it from the command line, a web-based tool, or anything
other than cron?

 For example, the script should create a marker file (or similar) when it
 runs, deleting the marker file upon completion.

Depending on the script, you may also be able to accomplish this with ps
instead:

ps ax | grep [m]y-script-name

If it returns anything, then at least one process named my-script-name
is already running, so abort.  (The [brackets] around the first letter
of my-script-name are to prevent grep my-script-name from appearing in
the output and creating a false positive.)

-- 
Dave Sherohman
NomadNet, Inc.
http://nomadnetinc.com/


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Cron - any advanced options?

2009-04-23 Thread Sjoerd Hardeman

Kurian Thayil wrote:

Hi All,
�
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?

You could create a lockfile
  touch /var/lock/cronfiletest
and the test if this lockfile exists, or else exit
  test -f /var/lock/cronfiletest || exit 0
You'll find similar tricks in many cron and init scripts.

Sjoerd

PS. Kurian, my apologies for the message sent to you. Hit the 'reply' 
vs. 'reply to list' button accidentally.




signature.asc
Description: OpenPGP digital signature