#!/bin/bash

# script rootPath
_script_root_=$(cd "$(dirname "$0")"; pwd)
_shname=`basename $0`

source /etc/profile

mkdir -p ${_script_root_}/logs

exec &>> ${_script_root_}/logs/${_shname%.sh}.log

if [ $# -gt 0 ]; then
    _deleteDay=$1
    _opsDay=`echo "${1}" |sed 's/-//g'`
else
    _deleteDay=`date -d "10 days ago" +%Y-%m-%d`
    _opsDay=`date -d "8 days ago" +%Y%m%d`
    _adlogdt=`date -d "5 days ago" +%Y-%m-%d`
    _adlgzdt=`date -d "21 days ago" +%Y-%m-%d`
fi


echo "==================`date "+%F %T"` $0  begin to delete ${_deleteDay} ${_opsDay} file=================="
if [ -d /export/logs/loggate ];then
  _num=`ls /export/logs/loggate/BiLogGate.${_deleteDay}-* |wc -l |awk '{print $1}' `
  /bin/rm -f /export/logs/loggate/BiLogGate.${_deleteDay}-*
  echo "`date "+%F %T"` delete BiLogGate.${_deleteDay}-* file num:${_num}"
else
  echo "`date "+%F %T"` not found /export/logs/loggate"
fi

if [ -d /export/client/rizhi/ops ];then
  _num=`ls /export/client/rizhi/ops/*/*_ClientLog_${_opsDay}_*.log |wc -l |awk '{print $1}' `
  /bin/rm -f /export/client/rizhi/ops/*/*_ClientLog_${_opsDay}_*.log
  echo "`date "+%F %T"` delete *_ClientLog_${_opsDay}_*.log file num:${_num}"
else
  echo "`date "+%F %T"` not found /export/client/rizhi/ops"
fi

if [ -d /export/scripts/advrsyncdir ];then
  _num=`ls /export/scripts/advrsyncdir/*/${_adlgzdt}/*.* |wc -l |awk '{print $1}' `
  /bin/rm -f /export/scripts/advrsyncdir/*/${_adlgzdt}/*.*
  echo "`date "+%F %T"` delete /export/scripts/advrsyncdir/*/${_adlgzdt}/ file num:${_num}"
else
  echo "`date "+%F %T"` not found /export/scripts/advrsyncdir"
fi

if [ -d /data/logs/advtracking/bi ];then
  _num=`ls /data/logs/advtracking/bi/advtracking.bi.${_adlogdt}*.log |wc -l |awk '{print $1}' `
  /bin/rm -f /data/logs/advtracking/bi/advtracking.bi.${_adlogdt}*.log
  echo "`date "+%F %T"` delete /data/logs/advtracking/bi/advtracking.bi.${_adlogdt}*.log file num:${_num}"
else
  echo "`date "+%F %T"` not found /data/logs/advtracking/bi"
fi

echo "==================`date "+%F %T"` $0  delete ${_deleteDay} ${_opsDay} end=================="
echo "`date "+%F %T"` $0  end"
