#!/bin/bash

source /etc/eltex-radius-db/three_years_radacct
source /usr/lib/eltex-radius-db/common_tools.sh

mklogdir

exec 2>> ${PARTITIONS_LOG}
exec >>  ${PARTITIONS_LOG}

/usr/lib/eltex-radius-db/partitioned_radacct_wrap.sh
if [ "$?" != "0" ]; then
    # Install mailutils, ssmtp
    # Configure /etc/ssmtp/ssmtp.conf and /etc/ssmtp/revaliases
    # Configure NOTIFICATION_ADDR at /etc/eltex-radius-db/manager-login
    if [ ! -z "$NOTIFICATION_ADDR" ]; then
        theme="Eltex SoftWLC: Daily operation with radacct partition finished with error! (host='${HOSTNAME}')"
        body=`/bin/cat "$PARTITIONS_LOG"`
        echoinfo "Start send error report to mail: '$NOTIFICATION_ADDR' ..."
        /bin/echo "$body" | /usr/bin/mail -s "$theme" $NOTIFICATION_ADDR
        echoinfo "Successful send error report to mail: '$NOTIFICATION_ADDR'"
    fi
fi
