#!/bin/bash

renice +19 -p $$ >/dev/null 2>&1
ionice -c3 -p $$ >/dev/null 2>&1

log='/var/log/purge_domlogs.log'
domlog_single_home='/home/apachelogs'
domlog_multi_home='/home1/apachelogs'

if [ -L "/usr/local/apache/logs/archive" ];then
   apachelog_dir=$(readlink /usr/local/apache/logs/archive)
else
   apachelog_dir='/usr/local/apache/logs/archive'
fi

#Purging archived domlogs
echo "Beginning purge domlogs $(date)" &>> ${log}
if [ -d ${domlog_multi_home} ]; then
   find ${domlog_multi_home} -maxdepth 2 -type f -name "*.gz" -mtime +365 -print -delete &>> ${log}
elif [ -d ${domlog_single_home} ]; then
   find ${domlog_single_home} -maxdepth 2 -type f -name "*.gz" -mtime +365 -print -delete &>> ${log}
fi

#Purging archived apachelogs
echo "Beginning purge apachelogs $(date)" &>> ${log}
if [ -d ${apachelog_dir} ]; then
   find ${apachelog_dir} -maxdepth 1 -type f -name "access_log-*.gz" -mtime +365 -print -delete &>> ${log}
   find ${apachelog_dir} -maxdepth 1 -type f -name "error_log-*.gz" -mtime +365 -print -delete &>> ${log}
   find ${apachelog_dir} -maxdepth 1 -type f -name "suexec_log-*.gz" -mtime +365 -print -delete &>> ${log}
fi
