
#!/bin/sh
# FIle	: cleanup_perfdata.sh
# By	: Maarten.deBoer@AtosOrigin.com, 101205
# Subject	: Cleanup the perfdata-dir of NetgApp-DFM, when filled up. Selectable past days

PGM="`basename $0|cut -d\. -f1`"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
RM=""
EC=""

touch ${LOG}

if [ "${1}" = "--remove" ]; then
  RM=1
fi

find /volumes/v2/NTAPdfm/perfdata -mtime +3 -print | while read FILE
do
  ls -l ${FILE}
  if [ $RM ]; then
    sudo rm ${FILE}
    EC=${?}
    if [ ${EC} -eq 0 ]; then
      echo "`date` ${PGM}: File ${FILE} has been removed " | tee -a ${LOG}
    else
      echo "`date` ${PGM}: Error (${EC}) while removing ${FILE} " | tee -a ${LOG}
    fi
  fi
done  # find


exit 0

