#!/bin/bash
#
# Version: 3.0
#

if [ "$1" != "cron" ]; then
	echo "This script is to be run by cron, not manually!"
	exit 1
fi

LOGDIR=/var/log/ucs

if [ -e /etc/ucs/ucs.conf ]; then
  source /etc/ucs/ucs.conf
  if [ ! -z "$LOG_FILENAME" ]; then
    LOGDIR=$(dirname $LOG_FILENAME)
	fi
fi

if [ ! -d $LOGDIR ]; then
  echo "Missing UCS log directory: $LOGDIR"
  exit 1
fi

YESTERDAY=`date +%F -d '1 day ago'`

cd $LOGDIR
for LOG in $(ls *.log); do
  if [ -f $LOG ]; then
    mv $LOG ${YESTERDAY}_$LOG
    gzip ${YESTERDAY}_$LOG
  fi
done
