#!/bin/sh
#
# user_job	Perform prologue/epilogue processing for Generic NQS
#		This script runs with the uid/gid of the owner of the
#		current batch job
#
#		WARNING: This script actually starts the current batch job!
#
#		All output from this script will be written to the stdout
#		and stderr staging files for the current batch job
#
# Here is what we know ...
#
#	DEBUG
#		Current GNQS debugging level
#
#	ENVIRONMENT
#		Always set to BATCH
#
#	HOME
#		Current user's home directory
#
#	Nqs_nmapdir
#	Nqs_libdir
#	Nqs_spooldir
#
#	QSUB_GID
#		GID of the owner of the current batch job
#
#	QSUB_HOST
#		Name of the current host
#
#	QSUB_QUEUE
#		Name of the current batch queue
#
#	QSUB_REQID
#		Request ID of the current batch job
#
#	QSUB_REQNAME
#		Name of the current batch job
#
#	NQS_SHELL
#		Shell to use to execute the current batch job
#	
#	QSUB_UID
#		UID of the owner of the current batch job
#
#	QSUB_USER
#		Name of the owner of the current batch job
#
#	QSUB_WORKING
#		Directory the job was submitted in?
#		Don't rely on this until thoroughly tested!
#
#	NQS_STDOUT
#		Name of the file to open for stdout
#
#	NQS_STDERR
#		Name of the file to open for stderr
#
# ///////////////////////////////////////////////////////////////////////////
#	PROLOGUE SECTION
# ///////////////////////////////////////////////////////////////////////////

# place your local modifications here

# ///////////////////////////////////////////////////////////////////////////
#	RUN CURRENT BATCH JOB SECTION
#
#	This section is supplied with Generic NQS - do not play with
#	unless you know what you are doing
#
#	WARNING :- your user's batch job will not execute if you break
#		   this section of the script
# ///////////////////////////////////////////////////////////////////////////

# =-=-=-=-=
#	First things first ...
#
#	Setup stdout and stderr if the appropriate environment vars are set
#       and the files do not exist yet.  This is usually caused by root not
#       having permissions on a NFS server, so do the exec ourselves.
if [ "$NQS_STDOUT+" != "+" ]; then
    if [ ! -f $NQS_STDERR ]; then
	if [ "$NQS_STDERR+" = "$NQS_STDOUT+" ]; then
	    exec > $NQS_STDOUT 2>&1
	else
	    exec > $NQS_STDOUT
	fi
    fi
fi

if [ "$NQS_STDERR+" != "+" -a "$NQS_STDERR+" != "$NQS_STDOUT+" ]; then
    if [ ! -f $NQS_STDERR ]; then
	exec 2> $NQS_STDERR
    fi
fi

#	Output a message that we have restarted this job if appropriate
if [ "$NQS_RESTART+" != "+" ]; then
	echo "GNQS: Job restarted at $NQS_RESTART"
	echo
fi

# yes, it really is this simple ...
# nqs_reqser.c makes it look a lot harder ;-)

$NQS_LIBEXE/nqssetargv $NQS_SHELL -`basename $NQS_SHELL`

# ///////////////////////////////////////////////////////////////////////////
#	EPILOGUE SECTION
# ///////////////////////////////////////////////////////////////////////////

# place your local modifications here
