Nginx 日志按日期切割

2018/07/11 by Jinyang | Filed under 技术相关.

1.   切割日志的脚本

 

#!/bin/bash

logs_path=”/usr/local/nginx/logs”

log_name=”access.log”

pid_path=”/usr/local/nginx/logs/nginx.pid”

YESTERDAY=$(date -d “yesterday” +%Y-%m-%d)

mv ${logs_path}/${log_name} ${logs_path}/access-${YESTERDAY}.log

kill -USR1 `ps axu | grep “nginx: master process” | grep -v grep | awk ‘{print $2}’`

find ${logs_path} -mtime +7 -name “*.log” | xargs rm -f

exit 0

 

2. 定时任务配置

0 0 * * * root /bin/sh /usr/local/nginx/logs/cut_nginx_log.sh


Leave a Reply

Your email address will not be published. Required fields are marked *

返回顶部