nginx日志分割

1.创建cut_nginx_log.sh

logs_path="/usr/local/nginx/logs/"

logs_names=(access error)

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

num=${#logs_names[@]}

for((i=0;i<num;i++));do

mv ${logs_path}${logs_names[i]}.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/${logs_names[i]}_$(date -d "yesterday" +"%Y%m%d").log

done

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

2.vi /etc/crontab

0 0 * * * root /usr/local/nginx/sbin/cut_nginx_log.sh

每天凌晨00:00执行

你可能感兴趣的:(nginx)