Browse Source

Mostly write job notification script

Samuel W. Flint 8 months ago
parent
commit
1f6e1db57e
1 changed files with 32 additions and 6 deletions
  1. 32 6
      in-progress/notify-job

+ 32 - 6
in-progress/notify-job

@@ -1,17 +1,43 @@
 #!/usr/bin/env bash
 
+ADDRESS=$1
+shift
+
 JOB=$1
-COMMANDFILE=$2
-ADDRESS=$3
+shift
+
+START_TIME=$(date)
+OUTPUT_FILE=$(mktemp)
+TIME_FILE=$(mktemp)
+
+env time -o ${TIME_FILE} /bin/sh $@ 2>&1 | tee ${OUTPUT_FILE}
 
-mkdir -p "~/jobs/${JOB}"
+END_TIME=$(date)
 
-/bin/sh "$COMMANDFILE" | tee "~/jobs/${JOB}/output"
+MESSAGE_FILE=$(mktemp)
 
-mail -s "Your Job is Complete" -a "~/jobs/${JOB}/output" "${ADDRESS}" <<EOF
+cat <<EOF > ${MESSAGE_FILE}
 The output of the command file is attached.
 
+Start time: ${START_TIME}
+End time: ${END_TIME}
+
+Process Time Statistics:
+EOF
+cat ${TIME_FILE} >> ${MESSAGE_FILE}
+
+cat <<EOF >> ${MESSAGE_FILE}
+
 JOB=${JOB}
-COMMANDFILE=${COMMANDFILE}
+COMMAND=$@
 ADDRESS=${ADDRESS}
 EOF
+
+cat ${MESSAGE_FILE}
+
+echo mail -s "Your Job is Complete" -a ${OUTPUT_FILE} "${ADDRESS}" < ${MESSAGE_FILE}
+
+
+rm ${MESSAGE_FILE}
+rm ${OUTPUT_FILE}
+rm ${TIME_FILE}