#!/bin/sh
#set -xv
#	This Bourne shell script launches the execution of the current
#	batch run configuration defined for the Group 1 software product,
#	MailStream Plus.  It expects no parameters; rather, the environment
#	must be defined by sourcing the product's setup file and then
#	the customer-defined run configuration file.  This script
#	starts the processing and immediately finishes -- the actual
#	run is processed as a background process tree immune to the
#	status of the terminal from which it was launched.

doit()
{
   $G1ECHO `date` -- Job $G1JOB started	# Log the time the job began
   $G1ECHO				# Log a blank line
					# Log the relevant environment variables

   set | egrep '^COB|^TMPDIR=|^LD_LIBRARY_PATH=|^EXTFH='
   $G1ECHO				# Log a blank line
   if [ "" != "$COBCONFIG" ]
   then	$G1ECHO "The COBCONFIG file contains:"
	cat $COBCONFIG
   fi
   $G1ECHO				# Log a blank line
   $G1MSP/bin/lsdds			# Log the status of the DD_ files
   $G1ECHO	`date` -- starting MSDR00

   $G1RTS/bin/runcbl -b $G1MSP/lib/MSDR00.acu

   cs=$?

   $G1ECHO	`date` -- MSDR00 ended with status $cs
   $G1ECHO				# Log a blank line
   $G1MSP/bin/lsdds			# Log the status of the DD_ files
   $G1ECHO `date` -- Job $G1JOB ended   # Log the time the job ended
   $G1ECHO "================================================================"

   cleanup
}

cleanup()
{
   . ${G1MSP}/bin/unsetDDs
   rm -f "${G1TMP}/${G1JOB}.pdt"
   rm -f "${G1TMP}/${G1JOB}.nns"
   rm -f "${G1TMP}/${G1JOB}.qso"
   rm -f "${G1TMP}/${G1JOB}.rzs"
   rm -f "${G1TMP}/${G1JOB}.ws1"
   rm -f "${G1TMP}/${G1JOB}.ws2"
   rm -f "${G1TMP}/${G1JOB}.ws3"
   rm -f "${G1TMP}/${G1JOB}.tmp"
   rm -f "${G1TMP}/${G1JOB}.wz1"
   rm -f "${G1TMP}/${G1JOB}.wz2"
   rm -f "${G1TMP}/${G1JOB}.tbl"
}

#  If the necessary variables are not defined, issue a message and exit:
: ${G1MSP:?} ${G1ECHO:?}

#  Process the jobname parameter...

if [ -z "$1" -o "$1" = "?" ]
then    $G1ECHO "\nThe syntax is:\n\n\trunmsp jobname\n"
        $G1ECHO "where jobname is the job identifier.\n"
        exit 1
fi

G1JOB=$1; export G1JOB

# doit      >       ${G1MSP}/data/${G1JOB}.log 2>&1 &
doit      >       ${G1MSP}/data/${G1JOB}.log 2>&1
