nginx 日志切割

参考资料:www.s135.com
vi cut-nginx-log.sh
 
#!/bin/bash

logs_path="/usr/local/nginx/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
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
 
效果如下
 
[root@shell]# tree /usr/local/nginx/logs/
/usr/local/nginx/logs/
|-- 2009
|     `-- 06
|             `-- access_20090610.log

日志会按照 年-月的的顺序记录日志