notify-job 619 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. mail -s "Your Job is Complete" -a ${OUTPUT_FILE} "${ADDRESS}" < ${MESSAGE_FILE}
  25. rm ${MESSAGE_FILE}
  26. rm ${OUTPUT_FILE}
  27. rm ${TIME_FILE}