#!/bin/sh

# Globus Job Manager LSF interface script for deleting a job
# Author:              Anzar Afaq & Igog Mandrichenko (FNAL)
# Last Modified:       08/09/2002
#
# This script uses information obtained from a file passed as the
# script's argument. This file contains a list of environment variables
# which are set by way of "sourcing" the file from this script. One of
# the evironment variables set as a result of this action is then used
# to obtain the job id for the job to be deleted. Once the job id
# is determined the LSF bkill command is used to delete the job.

. ${GLOBUS_LOCATION}/libexec/globus-script-initializer
 
globus_source ${libexecdir}/globus-gram-protocol-constants.sh
globus_source ${libexecdir}/globus-sh-tools.sh
globus_source ${libexecdir}/globus-gram-job-manager-tools.sh

#fbs=${GLOBUS_SH_BKILL-fbs}

#---------------------------------------------
# Set up FBSNG environment
#---------------------------------------------

. /fnal/ups/etc/setups.sh >/tmp/setups.out 2>/tmp/setups.err
setup fbsng

fbs=fbs  

arg_file=$1

        # Check for the argument file. If it does not exist
        # then return with an error immediately

if [ ! -f $arg_file ] ; then
   echo GRAM_SCRIPT_ERROR:$GLOBUS_GRAM_CLIENT_ERROR_BAD_SCRIPT_ARG_FILE
   exit 1
fi

        # Source the argument file to set environment variables
        # defining all the job arguments

. $arg_file

        # If a logfile name has been defined in then activate debug mode

if [ $grami_logfile = "/dev/null" ] ; then
    DEBUG_ECHO=:
else
    DEBUG_ECHO=echo
fi

#DEBUG_ECHO=echo
#grami_logfile=/tmp/anzar.tmp

$DEBUG_ECHO in gram_script_fbsng_rm >> $grami_logfile

	# Delete job using fbs kill command

$DEBUG_ECHO executing fbs kill with job id $grami_job_id >> $grami_logfile
${fbs} kill $grami_job_id

	# Only GRAM_SCRIPT_SUCCESS or GRAM_SCRIPT_ERROR from this script
	# is expected to be returned. The success or failure of the request
	# to delete the job is inconsiquencial.

echo GRAM_SCRIPT_SUCCESS:999

$DEBUG_ECHO "exiting gram_script_fbsng_rm\n\n" >> $grami_logfile


exit
