nginx每天定时分割日志

680 views

环境说明:
操作系统CentOS7.0,默认在线安装nginx。
nginx配置文件路径:/etc/nginx/nignx.conf,
nginx日志文件路径:/var/log/nginx/access.log
nignx.pid路径:/run/nginx.pid
新建的定时脚本位置/shell/nginx/logs.sh

1.新建脚本并执行

#mkdir /shell/nignx

#cd /shell/nginx

#vim logs.sh
#!/bin/bash

base_path='/var/log/nginx'

log_path=$(date -d yesterday +"%Y%m")

day=$(date -d yesterday +"%Y%m%d")

mkdir-p$base_path/$log_path

mv$base_path/access.log $base_path/$log_path/access_$day.log

#echo $base_path/$log_path/access_$day.log

kill-USR1`cat /run/nginx.pid`
#chmod a+X

#./logs.sh

2.定时执行(每天0点)

#crontab -e
#0 0 * * * /bin/bash /shell/nginx/logs.sh
#wq

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>