Nginx 日志切割

#多虚拟主机日志切割

#!/bin/bash


for logs_path in `cd /opt/logs && ls ./`

do 

   cd /opt/logs/${logs_path}

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

   mv access.log  ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log


done


kill -USR1 `cat  /opt/openresty/nginx/logs/nginx.pid ` 



#单个虚拟主机日志切割

#!/bin/bash


logs_path="/usr/local/webserver/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/webserver/nginx/nginx.pid`




# crontab -e 增加一个定时任务

0 0 * * * /bin/bash /usr/local/nginx/sbin/cut-log.sh


你可能感兴趣的:(nginx,日志,切割)