Create the log segmentation script virootcut_logs.sh #! Binbash # Thisscriptrunat00: 00 # TheNginxlogspathlogs_pathdatalogsmkdir-p $ {logs_path} $ (date-dyesterday + % Y) $ (date-dyesterday + % m) mv $ {logs_path} access. log $ {logs_path} $ (date
Create a log segmentation script vi/root/cut_logs.sh #! /Bin/bash # This script run at 00:00 # The Nginx logs path logs_path =/data/logs/mkdir-p $ {logs_path} $ (date-d yesterday + % Y) /$ (date-d yesterday + % m)/mv $ {logs_path} access. log $ {logs_path} $ (date
CreateLogsSplitScript
Vi/root/cut_logs.sh
#! /Bin/bash
# This script run at 00:00
# The Nginx logs path
Logs_path = "/data/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
/Usr/local/nginx/sbin/nginx-s reload
Set the execution permission of cut_logs.sh
Chmod + x/root/cut_logs.sh
Cut_logs.shAutomatic execution time
00 00 ***/root/cut_logs.sh