#!/bin/bash

OUTPUT='/tmp/statusmail.txt'
TIMEINT='2h'
START="$(date +%s)"
echo "" > ${OUTPUT}
log show --style syslog --last ${TIMEINT} | fgrep "Wake reason" | fgrep "Maintenance" >> ${OUTPUT2}
lines=`cat ${OUTPUT2} | grep -c '^'`
DURATION=$[ $(date +%s) - ${START} ]
echo "----| Shut Down Report |----" >> ${OUTPUT}
echo "" >> ${OUTPUT}
  echo "Occurances: $lines" >> ${OUTPUT}
  echo "Duration: ${DURATION}" >> ${OUTPUT}
  echo "Time Interval: ${TIMEINT}" >> ${OUTPUT}
  echo "------------------------------------------------------------------" >> ${OUTPUT}
  echo "" >> ${OUTPUT}
  echo "" >> ${OUTPUT}
  echo "" >> ${OUTPUT}
  echo "" >> ${OUTPUT}
  echo "------------------------------------------------------------------" >> ${OUTPUT}
  /usr/bin/python3 /Users/shughey/Dropbox/bin/send_status_mail3.py
rm ${OUTPUT}
osascript -e 'tell app "System Events" to shut down'
