其他分享
首页 > 其他分享> > 清理日志

清理日志

作者:互联网

#!/bin/sh


LOG_NAME="messages"
echo ' ' > $LOG_NAME

function loop_clean_log(){

  #LOG_NAME="PaasMainApp_*.log"
  BASE_DIR=`dirname $0` && cd $BASE_DIR
  USELESS_LOG_FILE=`find . -name "${LOG_NAME}-*" -type f -mtime +1`
  LOG_FILE=${BASE_DIR}/messages_clean.log
  
  cp ${LOG_NAME} ${LOG_NAME}-`date +%F-%T`
  echo ' ' > ${LOG_NAME}
  echo "dir name is: "`pwd`
  echo "useless log file: "$USELESS_LOG_FILE
  
  rm -f ${USELESS_LOG_FILE} 2>&1
  if [ $? -eq 0 ]
  then
    echo `date`==="日志清理成功" >> ${LOG_FILE}
    echo ${USELESS_LOG_FILE} >> ${LOG_FILE}
  else
    echo `date`==="日志清理失败" >> ${LOG_FILE}
  fi
}

while [ 1 ]
do
  loop_clean_log
  sleep 12h
done

标签:NAME,清理,USELESS,echo,log,FILE,日志,LOG
来源: https://www.cnblogs.com/fan-gx/p/11745785.html