#!/usr/bin/env bash
#
#  This is a highly technical and subtle script.  Edit at your own risk!
#
#  Generally this should be run via the crontab line:
#            0 12 * * * /abs/path/to/file/sos_apospammer
#
#  Written by Gary Kushner (LBL).  Jan 2010.

#- If there is any message other than just "Log Rolled", send an email
if [ "`cat /home/eboss/sos/logs/sos_log-b1-error`" != "Log Rolled" ] ; then
    mail StephenBailey@lbl.gov,jonathan.richards@utah.edu -s "SOS Critical Error Log" < /home/eboss/sos/logs/sos_log-b1-error
fi

#
###  The python logger doesn't roll over the log unless it writes to it.  So unless
###  there is a critical error, the same log will be sent over and over.  This is a
###  hack to roll them manually to the email makes more sense
#

cp /home/eboss/sos/logs/sos_log-b1-error-2 /home/eboss/sos/logs/sos_log-b1-error-3
cp /home/eboss/sos/logs/sos_log-b1-error-1 /home/eboss/sos/logs/sos_log-b1-error-2
cp /home/eboss/sos/logs/sos_log-b1-error /home/eboss/sos/logs/sos_log-b1-error-1

cat >/home/eboss/sos/logs/sos_log-b1-error <<< "Log Rolled"
