Nginx 日志按日期分割日志,并定期删除

nginx日志分割  

cut_nginx_logs.sh

#!/bin/bash
#0 0 * * *  /bin/bash /root/scripts/cut_nginx_logs.sh
logs_path="/data/logs/"

cd $logs_path  
for i in *.log  
do  
    logspath=$logs_path/$(date "+%Y%m")/$(date "+%d")
    mkdir -p $logspath
    mv $i $logspath/$(date "+%H_%M_%S").$i
done

if [ -d $logs_path ];then  
    find $logs_path -mtime +15 -exec rm -f {} \;
fi

kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`