
#!/bin/sh
# FIle	: clean_asup_dir.sh
# By	: Maarten.deBoer@Atos.net, 160930
# Subject	: Script to clean AUSP-dir
#(0.2)	: Mod's
PGM="`basename $0|cut -d\. -f1`"
VER="0.2"
DATI="`date +%Y-%m-%d-%H-%M-%S`"
TMP="/tmp/${PGM}.${DATI}"
LOG="${HOME}/log/${PGM}.log"

ASUPDIR="/appl/asup/data"
ASUPDIR="/appl/asup/mail-proc"

DAYS=365
#DAYS=300
DAYS=250
#DAYS=200

echo "`date` ${PGM} v${VER} (DAYS=${DAYS}) started."|tee -a ${LOG}
cp /dev/null ${TMP}

cd ${ASUPDIR}
df -h ${ASUPDIR}|tee -a ${LOG}

# Get files to be removed
ls -1|while read DIR
do
  if [ -d ${ASUPDIR}/${DIR} ]; then
    echo "# Getting file in ${ASUPDIR}/${DIR} ..."|tee -a ${LOG} ${TMP}
    find ${ASUPDIR}/${DIR} -mtime +${DAYS} >> ${TMP}
  fi  # -d
done  # ls -1

# Clean (remove files)
echo "  Cleaning from file ${TMP}"
cat ${TMP}|grep -v ^#|while read FILENAME
do
  echo ${FILENAME}
  rm ${FILENAME}
done  # cat ${TMP}

df -h ${ASUPDIR}|tee -a ${LOG}

echo "TMP=${TMP}"|tee -a ${LOG}
echo "`date` ${PGM} v${VER} finished."|tee -a ${LOG}
exit 0

