编写每天定时切割Nginx日志的脚本

1、创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh,输入以下内容:

#!/bin/bash

# This script run at 00:00

 

# The Nginx logs path

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`

 

2、设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

输入以下内容:

00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

 

你可能感兴趣的:(nginx)