1. script nginx_log.sh
#! / bin / bash #nginx installation address BASE_PATH = / usr / local / nginx # log file name TARGET_LOG_FILENAME = access.log # write folder address OUT_PATH = / usr / local / nginx / logs / backup_log # when Folder it does not exist create IF [-d! " $ OUT_PATH " ]; the then mkdir $ OUT_PATH fi # create a log file name based on date, this is divided according to months NEW_LOG_FILENAME = $ (/ bin / dATE -d Yesterday +% Y_ % m) # this is in accordance min # / bin / DATE -d Yesterday the Y% m%% +% H% D m # 2020_01_access.log log OUT_PATH_FILENAME= $ NEW_LOG_FILENAME " _ " $ TARGET_LOG_FILENAME # stop nginx $ BASE_PATH / sbin / nginx - S STOP echo " creates a log file " $ NEW_LOG_FILENAME echo $ OUT_PATH / $ OUT_PATH_FILENAME # move the log files mv $ BASE_PATH / logs / $ TARGET_LOG_FILENAME $ OUT_PATH / $ OUT_PATH_FILENAME Touch $ BASE_PATH / logs / $ TARGET_LOG_FILENAME # start nginx logs $ BASE_PATH / sbin / nginx
2. Task Scheduler crontab -e
0 0 1 * * /bin/sh /usr/local/nginx/logs/nginx_log.sh > /dev/null 2>&1 &