#!/usr/bin/env bash

JOB=$1
COMMANDFILE=$2
ADDRESS=$3

mkdir -p "~/jobs/${JOB}"

/bin/sh "$COMMANDFILE" | tee "~/jobs/${JOB}/output"

mail -s "Your Job is Complete" -a "~/jobs/${JOB}/output" "${ADDRESS}" <<EOF
The output of the command file is attached.

JOB=${JOB}
COMMANDFILE=${COMMANDFILE}
ADDRESS=${ADDRESS}
EOF
