# 编写切割脚本 # vim /data0/scripts/cut_nginx_log.sh #!/bin/bash logs_path="/data0/log/nginx" YDATE=`date +"%Y"` MDATE=`date +"%m"` DDATE=`date -d"1 day ago" +"%d"` HDATE=`date +"%H"` mkdir -p ${logs_path}/${YDATE}/${MDATE}/${DDATE}/ yesterday=`date -d "yesterday" +"%Y%m%d"` for logname in `find ${logs_path} -maxdepth 1 -name "*.log"` do domain=`echo $logname | sed "s#/data0/log/nginx/##"` mv ${logs_path}/$domain ${logs_path}/${YDATE}/${MDATE}/${DDATE}/$domain\_${yesterday}.log done /usr/local/nginx/sbin/nginx -s reload find ${logs_path} -name "*.log" -mtime +15 -exec rm -fr {} \; # 添加执行权限 chmod +x /data0/scripts/cut_nginx_log.sh # 添加计划任务 # crontab -l 0 0 * * * cd /data0/scripts && /bin/sh cut_nginx_log.sh >/dev/null 2>&1
时间: 2024-12-06 11:18:10