#!/bin/bash

# exit this script if any error occurs
set -e

# get the directory where this script is in
SCRIPTDIR="$(realpath -s $(dirname $0))"

# set the output file
RESULTFILE="${SCRIPTDIR}/my_results.txt"

# check if on login node
HOST="$(hostname)"
if [[ $HOST = login* ]]; then
  echo "ERROR: No heavy computations on the login node!"
  exit 1
fi

echo "### starting 'heavy' computation ###"

echo -e "
HOSTNAME=$HOST
USER=$USER
PWD=$PWD
SLURM_JOB_ID=$SLURM_JOB_ID

--------------------------------------------------
" > "${RESULTFILE}"

scontrol show job --detail $SLURM_JOB_ID >> "${RESULTFILE}"

cat "${RESULTFILE}"

echo "### 'heavy' computation done ###"

# exit the script with zero exit code
exit 0
