一、nacos历史日志文件删除脚本
logFile="/root/shell/nacos_del_access.log"
//昨天
date=`date -d "$date -1 day" +"%Y-%m-%d"`
//匹配昨天的access_log日志
delFilePath="/usr/local/youxianxin/nacos/logs/access_log.${date}.log"
curDate=`date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"`
if [ ! -f "${logFile}" ];then
touch ${logFile}
fi
if [ -f "${delFilePath}" ];then
rm -rf ${delFilePath}
echo '['${curDate}'] 删除文件'${delFilePath} >>${logFile}
fi
echo '['${curDate}'] 删除了以下*.log.*.0格式文件' >> ${logFile}
ls -l /usr/local/youxianxin/nacos/logs/*.log.*.0 | awk '{print $9}' >> ${logFile}
rm -rf /usr/local/youxianxin/nacos/logs/*.log.*.0
凌晨1点执行该脚本:
00 01 * * * sh /root/shell/log_clean.sh
#! \bin\bash
###用于定时清除nacos今天之前的日志文件
logFile="/root/shell/nacos_del_access.log"
date=`date -d "$date -1 day" +"%Y-%m-%d"`
delFilePath="/usr/local/youxianxin/nacos/logs/access_log.${date}.log"
curDate=`date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"`
if [ ! -f "${logFile}" ];then
touch ${logFile}
fi
if [ -f "${delFilePath}" ];then
rm -rf ${delFilePath}
echo '['${curDate}'] 删除文件'${delFilePath} >>${logFile}
fi
echo '['${curDate}'] 删除了以下*.log.*.0格式文件' >> ${logFile}
ls -l /usr/local/youxianxin/nacos/logs/*.log.*.0 | awk '{print $9}' >> ${logFile}
rm -rf /usr/local/youxianxin/nacos/logs/*.log.*.0