创建日志分割脚本
vi /root/cut_logs.sh
#!/bin/bash
#This script run at 00:00
# The Nginx logs path
logs_path="/data/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
/usr/local/nginx/sbin/nginx -s reload
设置 cut_logs.sh执行权限
chmod +x /root/cut_logs.sh
cut_logs.sh 自动执行时间
00 00 * * * /root/cut_logs.sh