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

nginx日志分割  

cut_nginx_logs.sh

#!/bin/bash
#0 0 * * *  /bin/bash /root/scripts/cut_nginx_logs.sh
logs_path="/data/logs/"  
today=$(date "+%Y%m%d")  
cd $logs_path  
for i in *.log  
do  
    mv $i ${today}-$i
    tar zcf ${today}-${i}.tar.gz ${today}-$i && rm -f ${today}-$i
done

if [ -d $logs_path ];then  
    find $logs_path -name "*.tar.gz" -mtime +15 -exec rm -f {} \;
fi

kill -USR1 `cat  /data/soft/nginx/logs/nginx.pid`