美文网首页
nginx日志切割

nginx日志切割

作者: vincent浩哥 | 来源:发表于2019-10-18 20:27 被阅读0次
  • 需求
    nginx的日志文件路径
    每天0点对nginx 的access与error日志进行切割
    以前一天的日期为命名

  • 脚本

#!/bin/bash
#Auto cut nginx log script.
#create by vincent
#create date:2019-10-12
#nginx日志路径
logs_path=/usr/local/nginx/logs
YesterDay=$(date -d 'yesterday' +%Y-%m-%d)

#移动日志并以日期改名
mv ${logs_path}/access.log ${logs_path}/access_${YesterDay}.log
mv ${logs_path}/error.log ${logs_path}/error_${YesterDay}.log

#向nginx主进程发送信号,重新生成日志文件
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
  • 定时器执行配置
    0 0 * * * /home/nginxLog/nginx_access_log.sh

相关文章

网友评论

      本文标题:nginx日志切割

      本文链接:https://www.haomeiwen.com/subject/wbtqmctx.html