notify-job 645 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. ADDRESS=$1
  3. shift
  4. JOB=$1
  5. shift
  6. START_TIME=$(date)
  7. OUTPUT_FILE=$(mktemp)
  8. TIME_FILE=$(mktemp)
  9. env time -o ${TIME_FILE} /bin/sh $@ 2>&1 | tee ${OUTPUT_FILE}
  10. END_TIME=$(date)
  11. MESSAGE_FILE=$(mktemp)
  12. cat <<EOF > ${MESSAGE_FILE}
  13. The output of the command file is attached.
  14. Start time: ${START_TIME}
  15. End time: ${END_TIME}
  16. Process Time Statistics:
  17. EOF
  18. cat ${TIME_FILE} >> ${MESSAGE_FILE}
  19. cat <<EOF >> ${MESSAGE_FILE}
  20. JOB=${JOB}
  21. COMMAND=$@
  22. ADDRESS=${ADDRESS}
  23. EOF
  24. cat ${MESSAGE_FILE}
  25. echo mail -s "Your Job is Complete" -a ${OUTPUT_FILE} "${ADDRESS}" < ${MESSAGE_FILE}
  26. rm ${MESSAGE_FILE}
  27. rm ${OUTPUT_FILE}
  28. rm ${TIME_FILE}