crontab entry environment variables [PSARC/2007/503 FastTrack timeout09/10/2007]

Roland Mainz roland.mainz at nrubsig.org
Mon Sep 10 09:31:43 PDT 2007


Darren J Moffat wrote:
> 
> I'm sponsoring this OpenSolaris case for Chris Gerhard. It has some possible
> standards impact but I believe based on previous discussions this should
> be acceptable, if it wasn't for the standards impact this would likely have
> been self-review.
> 
> Template Version: @(#)sac_nextcase 1.64 07/13/07 SMI
> This information is Copyright 2007 Sun Microsystems
> 1. Introduction
>     1.1. Project/Component Working Name:
>          crontab entry environment variables
>     1.2. Name of Document Author/Supplier:
>          Author:  Chris Gerhard
>     1.3  Date of This Document:
>         03 September, 2007
> 4. Technical Description
> 
> This project proposes support for and use of TZ, SHELL and HOME
> variables as per crontab(4) entry varaiables, these are the only ones
> that change the way cron behaves.  All others can be achieved via
> having the entry set the variable (SHELL is the weakest of the three to
> change as it only saves on exec).
> 
> HOME solves the problems associated with NFS and cronjobs where a users
> home directory is not available when the entry runs (as in the case with
> secure NFS).
> 
> TZ obviously sets the time zone when the entry is valid. Allowing jobs
> to run in any time zone.
> 
> The variables continue to effect all entries below them until new
> entries are listed in the file. Entries would run with a HOME directory
> set to the one listed and at times that are correct according to the TZ
> value and with a shell specified by SHELL.
> 
> Setting any other variable results in an error when you try and save
> the crontab file.
> 
> Use of this facility is controlled by an entry in the already existing
> /etc/default/cron [ the project team is aware that ideally this and the
> existing cron(1M) use of this file should migrate to SMF properties but
> that is not this case ]. If there is an entry of the form:
> 
>         ALLOW_EXTENSIONS=YES

1. What will happen if new extensions are added ? IMO this should
include a version number or something similar to make sure syntax
extensions can be added later...

2. I have great concerns about the abuse of the global environment
variable namespace - sooner or later this will backfire _badly_ if cron
and other applications have slightly different ways to interpret the
values.

What about the following solution:
-- snip --
The following variables are supported ("cron"-specific variable live in
a seperate variable "namespace" starting with ".cron." followed by the
variable name):

".cron.home": This allows the user to choose and alternative  direc-
tory  for cron  to change directory to prior to running the
command.

For example

  .cron.home=/var/tmp

".cron.shell": The name of the shell to use to run the commands. Eg:

  .cron.shell=/usr/bin/ksh

".cron.tz": This allows the user to choose        the timezone in which
the
cron  entries are run.  This effects both the environment of
the command that  is run  and the timing of the entry.  For
example to have your entries run using the timezone for Ice-
land:

 .cron.tz=Iceland

Variables starting with any other valid variable charatcers than "." are
exported to the launched cron session, e.g.

  TODAYS_MEAL=giraffe

will set the variable "TODAYS_MEAL" to the value "giraffe" in the
process environment when the cron job is lanuched.

The rest of the lines are the same as crontab  entries  that
conform to the UNIX standard.
-- snip --
As a side-effect we could define any extra variable name within ".cron."
without running into problems with variable name collisions, e.g. the
system is extensible (for example ".cron.mailto" could be added later).

A precedent for this can be found in ksh93 which uses the
".sh."-namespace to store shell-specific implementation details (like
".sh.version" etc.) outside the normal variables.

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)



More information about the opensolaris-arc mailing list