nginx日志切割

1. 在 /scripts 目录 创建脚本 cut_log.sh 编写如下:

#-------------------------------------------------------------#
#!/bin/bash
#用于切割nginx访问日志
if [ ! -d "/application/nginx/logs/history" ]; then
  mkdir -p /application/nginx/logs/history
fi

LOGS_PATH=/application/nginx/logs/history
CUR_LOGS_PATH=/application/nginx/logs
shijian=$(date -d "yesterday" +%Y-%m-%d)
mv ${CUR_LOGS_PATH}/access.log ${LOGS_PATH}/chenleilei_access_${shijian}.log

##向nginx主进程发送USR1的重载信号,USR1就是重新打开日志文件
kill -USR1 $(cat /application/nginx/logs/nginx.pid)
#-------------------------------------------------------------#

保存为cut_log.sh 并添加可执行权限:
chmod +x cut_log.sh


2.添加计划任务 每天晚上0点执行【centos7计划任务文件/etc/crontab】
echo "00 00 * * * /bin/bash /scripts/cut_log.sh" >> /etc/crontab
原文地址:https://www.cnblogs.com/superlinux/p/12719045.html