[Gllug] Advanced versions of cron for scheduling

Minty mintywalker at gmail.com
Fri Jul 15 20:10:02 UTC 2005


fwiw, i'm sure you are after something tidier than my little brain can
come up with:

> (1) Run one job straight after another/some others have finished.
> 
> This can be done using script1 && script2, but what if we want a job
> to run after several other jobs have finished, provided they all
> finish successfully.  And in a maintainable fashion.

bash script, wrapping each call in "if job else exit" blocks?

> (2) Run a job continually - after it finishes, schedule it to run
> again.
> 
> A shell script, while true; do ... done, solves this, but there are
> maintainability concerns (eg for one, how to start the script when the
> machine boots, from a non-root user account, without requiring root
> access?).

apache can be started in this manner, using a non root account.... ?
dunno how...

> (3) Set a time limit on a job.
>
> If it exceeds the time limit, either send mail warning about this, or
> kill it -- we'd want to control which, because sometimes killing a job
> can result in loss of data, for reasons outside of our control.

#!/usr/bin/perl

eval {
  local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
  alarm $timeout;
  # do stuff....
  alarm 0;
};
if ($@) { ...send alert email or whatever... }

> (4) Running jobs regularly, but at odd intervals.
> 
> For example, one request I've had was to run a job every 45 minutes.
> This isn't easy to express in a crontab.

"at" command wrapped in a bash script?

starttime = now 
do stuff
delta = 45 mins - (now - starttime)
at ./this_batch_script.sh delta 

> (5) Keep the crontab file under CVS control.

1 entry in crontab : every min, call master_wrapper.sh
put all your other entries in master_wrapper and pop that into cvs
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list