kavin

nginx日志切割

kavin nginx 2018-05-04 2592浏览 0

具体脚本内容如下:


#!/bin/bash

# This script run at 00:00
 
# The Nginx logs path
logs_path="/usr/local/nginx/logs"
pid=`ps -ef|grep -v grep|grep nginx|grep master|awk '{print $2}'`
 
mv ${logs_path}/nginx_access.log ${logs_path}/nginx_access_$(date -d "yesterday" +"%Y%m%d").log
mv ${logs_path}/nginx_error.log ${logs_path}/nginx_error_$(date -d "yesterday" +"%Y%m%d").log
#kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
kill -USR1 "$pid"
cd $logs_path
/usr/bin/zip -r nginx_access_$(date -d "yesterday" +"%Y%m%d").zip nginx_access_$(date -d "yesterday" +"%Y%m%d").log
/usr/bin/zip -r nginx_error_$(date -d "yesterday" +"%Y%m%d").zip nginx_error_$(date -d "yesterday" +"%Y%m%d").log
/bin/rm -rf nginx_access_$(date -d "yesterday" +"%Y%m%d").log
/bin/rm -rf nginx_error_$(date -d "yesterday" +"%Y%m%d").log


写好脚本后执行

转载请注明:IT运维空间 » nginx » nginx日志切割

发表评论