#!/usr/bin/env bash
#
# Submit jobs to Univa Grid Engine.
#
# Manual: http://gridengine.eu/mangridengine/manuals.html

set -o errexit
set -o pipefail
set -o nounset

readonly LOG_PATH='/home/rodrigo/log'
readonly ARCHIVE_PATH="$LOG_PATH/archive"

echo "Change directory to log ($LOG_PATH) to save results in this directory"
cd "$LOG_PATH"

echo "Creating directory to archive past log files under $ARCHIVE_PATH, if it does not exist"
mkdir -p "$ARCHIVE_PATH"

echo "Archiving past log files ($LOG_PATH/lrppf.*) under $ARCHIVE_PATH"
# Check if any files need to be archived
# Source: https://stackoverflow.com/a/6364244
if ls "$LOG_PATH"/lrppf.* >/dev/null 2>&1; then
  mv "$LOG_PATH"/lrppf.* "$ARCHIVE_PATH"
fi

echo "Submit experiment jobs. Enabling verbose mode using bash opt xtrace."
set -o xtrace
qsub -m esa -M r.bermudezschettino@campus.tu-berlin.de /home/rodrigo/experiments/cluster/script/run-lrp-pf.sh
set +o xtrace
