Batch Run Time Environment
BRTE Technical Reference


Overall Design Issues

These modules are designed to be used by programs running in the BRTE. BRTE programs are written in ksh. These functions are only supported for the korn shell, i.e. ksh.

These functions tend to build upon one another. For instance, the do_command function relies on the check_execute function which in turn relies on the print_to_log function.

The BRTE program functions are defined to the program by including the file batch_modules. This would be done by the following syntax:

      . /opt/brte/batch_modules

The BRTE entry point batch_modules takes two optional arguments.

A -a can be specified which changes the logging behaviour of the program. The default behaviour is to create a log for each execution of the program. With this option a single log is created for all executions of the program within a 24 hour period.

The -d option requires a parameter that specifies an alternative brte directory. This option is primarily aimed for debugging brte itself. However, it can be used in an emergency situation if a bug is found in the prodution copy installed on a system. A copy of the production brte installation can be made and modified and then the program that failed modifed so that it uses this option to use the copied brte. This option should not be used in normal production programs.

These functions assist in the implementation of BRTE. (See the BRTE Documentation for details.) Primarily this is done by assigning values to the abstract system definition defined in the BRTE documentation.

There is certain information that BRTE cannot know for every application. This information like the application, what DB servers that it uses, etc must be passed to BRTE in a standard way. The mechanism that BRTE uses is to read the file $HOME/brte_profile as soon as batch_modules is called. For system accounts this file will contain environment variable definitions like SYSTEMNAME and ORA_SERVERS. Developer accounts should have some logic in this file that will result in the appropriate definitions for the same variables. (See the BRTE Examples for more details.)

A base set of application variables must be set before BRTE functions can assign the proper values of the ASD (Abstract System Definition). These values are set in $HOME/brte_profile. If the BRTE functions detect that these application variables are not set, then they will force an error immediately.

Variable Name

Description

SYSTEMNAME

Required by BRTE. Denotes the application identifier. Used by nearly all other layers of BRTE. This should be set readonly.

SYSTEMHOME

Required by BRTE. Denotes the 'HOME' directory for the application. It should be set readonly. This is really an artifact left from the development environmt. In a typical production or test environment, this will be equal to the $HOME for that account. However, for a developer it is likely to be much different.

In addition to the requisite variables above, there are a set of variables that control the execution of certain functions. Various functions will behave differently depending on how or if these variables are set. These variables can be set by the developer within the program. Another method is to use the $HOME/brte_profile to set some of these variables. By using this method, code does not need to change as a script migrates from one environment to another. Below is a list of variables that should be defined in $HOME/brte_profile if they are required by a program.

Variable Name

Description

APPBIN

Location of application specific binaries. The files could actually be links to older versions of the programs that are still on the system but are considered non-standard versions. A good location might be $SYSTEMHOME/bin.

ORA_SERVERS

This is a space delimited list of oracle instances the program expects to use. This is a required variable for some connection function functions.

ORACLE_HOME

Denotes the base home directory for the Oracle instance that the application uses. Required for some functions in batch_modules.

PERL5LIB

Specifies location of additional perl modules that the program may use.

SQRDIR

The default location of SQR utilities. This varaible is used by SQR utilities.

SYB_SERVERS

This is a space delimited list of sybase servers the program expects to use. This is a required variable for some connection function functions.

SYBASE

This denotes the default location to find Sybase interface file and various utilities. Required for some functions in batch_modules.

The following variables are also used by BRTE but can be set anywhere inside a program. These variables do not need to change depending on what environment i.e. production, QA test, unit testing, development.

Variable Name

Description

ALWAYS_RETURN

If this variable contains an non-zero value, then check_execute will always return rather than calling end_run itself. It is up to the programmer in this situation to take appropriate action when an error has occurred.

ENDSTEP

The executor function uses this variable to determine the last step to execute in the program. If the variable is defined, it must inclusively be between 1 and the number of steps in the program. Otherwise executor will flag an error in the execution.

STARTSTEP

The executor function uses this variable to determine which step to start executing the program. If the variable is defined, it must inclusively be between 1 and the number of steps in the program. Otherwise executor will flag an error in execution.

Functions

The functions are defined by calling in the program batch_modules. In addition batch_modules sets the variables in Table 1. Some of these variables are read-only. batch_modules is written to be re-entrant though. If a chain of programs each call batch_modules, the first program will set the automatic read-only variables for the subsequent programs. For instance no new log file will be created. The children programs will all write to the parent's log file.

    batch_modules

    batch_modules [-a] [-d <alternate BRTE location>]

This is the entry point for BRTE. This is actually a program that sourced directly into the target program. batch_modules is responsible for defining all the resources that other BRTE functions will rely on. It performs the following tasks:

  1. Check if batch_modules has been previously called. If it has it returns a 0 and allows the calling program to continue.

  2. Process options passed.

  3. Inline run the $HOME/brte_profile file.

  4. Define all BRTE required variables and defaults for other BRTE variables where applicable.

  5. Mark application functions in $SYSTEMHOME/lib/brte for autoloading.

  6. Mark BRTE functions for autoloading.

  7. Initialize log file and checks for success.

  8. Checks to see if program has been WNR'd.

  9. Returns control to the calling program.

-a Normally BRTE creates a new log file each time the program is executed. This option changes that behavior so that no more than one log file is created per day. This should be used for programs that are frequently executed during the day, i.e. 3 or more times per day.

-d Specifies an alternate location for the BRTE functions. Usually used only when debugging BRTE itself, but could be used in an emergency in production.

batch_modules will either return a 0 or will panic. It may put certain warnings into the log if it discovers them.

Variable Name

Description

Assignment Logic

Read Only

BRTEBIN

B

C

D

BRTE_DEBUG

B3

C3

D3

CURTIME

B3

C3

D3

EMAIL_LIST

B3

C3

D3

ERRCLASS

B3

C3

D3

ERRMESG

B3

C3

D3

EXECTIME

B3

C3

D3

LOGDIR

B3

C3

D3

OPMAIL

B3

C3

D3

OPPAGE

B3

C3

D3

PAGER_LIST

B3

C3

D3

PATH

B3

C3

D3

PROGRAMDIR

B3

C3

 

REDSCHEDIR

This is the directory from which redschedule programs are executed. In addition, modified copies of scripts used for restarts should be placed in this directory. Files older than 30 days in this directory are deleted, but are retained in the backup system for another 90 days.

REDSCHEDIR = "$SYSTEMHOME/redschedir";
typeset -rx REDSCHEDIR

yes

SCRIPT_NAME

This is an immutable variable denoting the base name of the program. It contains no reference to the directory in which the program resides.

SCRIPT_NAME = `basename $0`;
typeset -rx SCRIPT_NAME

yes

SCRIPTLOG

his is an immutable variable containing the fully qualified name of the log for the current execution of the program. The file name is of the form: program_name:YYYYMMDD:HH:MM:SS:PID

SCRIPTLOG = "$LOGDIR/$SCRIPT_NAME:$EXECTIME:$$";
typeset -rx SCRIPTLOG

yes

SCRIPTPID

Process ID of the script as it is currently running.

SCRIPTPID = $$; typeset -xr SCRIPTPID

yes

SECUREDIR

Location of security maintained files.

ECUREDIR = /opt/sa_forms/pass;
typeset -xr SECUREDIR

yes

STAGINGDIR

This is a directory for input or output from the program that is for other steps or programs. Files older than seven days are deleted from this location.

STAGINGDIR="/staging/$SYSTEMNAME";
typeset -rx STAGINGDIR

yes

STATUS

This immutable variable denotes whether the program is executing in a production or test environment. The code in batch_modules is actually different between production and test systems when it comes to assigning this value.

STATUS="PROD|TEST";
typeset -rx STATUS

yes

WORKDIR

This is a directory to which an application can do temporary IO. Files older than 24 hours are deleted from this location. Generally only IO needed within a step should occur here.

export WORKDIR=/tmp

 

USERNAME

This is the unix account name that program is running under.

USERNAME=$LOGNAME;
typeset -rx USERNAME

yes

*Assignment logic is specified in ksh syntax.