3.39. Nginx日志切割脚本

3.39.1. 示例1

#!/usr/bin/env bash
#usage:xxx
#scripts_name:xxx.sh
# author:xiaojian

S_LOG=/usr/local/nginx/logs/access.log
D_LOG=/data/backup/`date +%Y-%m-%d`
echo -e "\033[32mPlease wait start cut shell scripts ....\033[0m"
sleep 2

if [ ! -d $D_LOG ]; then
    mkdir -p $D_LOG
fi

mv $S_LOG $D_LOG
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
echo "---------------------------------------------"
echo "The Nginx log Cutting Successfully! "
echo "You can access backup nginx log ${D_LOG}/access.log files."

3.39.2. 示例2

#!/bin/sh
#nginx日志切割

#设置
Log_path=/www/server/nginx/logs
Yesterday=$(date -d "yesterday" +%Y-%m-%d_%S)
Nginxbin=/www/server/nginx/sbin/nginx

#日志改名
/bin/mv $Log_path/access.log $Log_path/access.$Yesterday.log
/bin/mv $Log_path/error.log  $Log_path/error.$Yesterday.log

#重新生成日志
$Nginxbin -s reopen

# #定时任务
# #nginx日志切割
# 00 00 * * *  /root/sh/cut_log.sh
# #

canker文献 https://www.cnblogs.com/elvi/p/7717986.html