#!/bin/sh
#BSUB -n @@{NNODES}
#BSUB -W @@{WALLTIME}
#BSUB -J JOB_@@{JOBID}_@@{INSTANCEID}
#BSUB -o lsf_@@{RUNNAME}_@@{INSTANCEID}.stdout
#BSUB -e lsf_@@{RUNNAME}_@@{INSTANCEID}.stderr
@@{REMOTEBATCHACCOUNT}

@@{ENVIRONMENT}

# RemoteBatchLSF:makeSerialTemplate
# SubmissionScripts/Distributor/Batch/LSF/serial

trap cleanup HUP INT QUIT ABRT TERM

cleanup()
{
   echo "Abnormal termination by signal"
   if [ ! -s @@{TS_FINISH} ] ; then
      date +"%s" > @@{TS_FINISH}
   fi
   exit 1
}

TIMEPATH=
for timePath in ${HOME}/bin/time /usr/bin/time /usr/local/bin/time ; do
   if [ -x ${timePath} ] ; then
      TIMEPATH=${timePath}
      break
   fi
done

@@{QUOTA}

date +"%s" > @@{TS_START}

@@{PREMANAGERCOMMANDS}
${TIMEPATH} --format "Command exited with status %x\nreal %e\nuser %U\nsys %S" -o @@{TIME_RESULTS} \
   @@{EXECUTABLE} @@{ARGUMENTS} < @@{STDIN} > @@{RUNNAME}_@@{INSTANCEID}.stdout 2> @@{RUNNAME}_@@{INSTANCEID}.stderr
@@{POSTMANAGERCOMMANDS}

date +"%s" > @@{TS_FINISH}
