Nginx splits logs by day, and nginx splits logs
#! /Bin/bash # Cut and compress nginx logs by day, add crontab to cut at every day # Author: fafu_li # Time: 2015.08.15source/etc/profile # load the system environment variable source ~ /. Bash_profile # load the user environment variable set-o nounset # reference the uninitialized variable and exit set-o errexit # exit PID = "/usr/local/nginx/logs when an error occurs during shell Command Execution /nginx. pid "# pid directory NGINX ="/usr/local/nginx/sbin/nginx "YESTERDAY = $ (date-d" yesterday "+ % Y-% m-% d) # Yesterday's LOGS_PATH = "/data/nginx/logs" # log directory server_names = ("access_chaoneng ") # log name server_count =$ {# server_names [@]} # split the log cut_logs () {local name = $1 cd $ LOGS_PATH/bin/mv-f $ {name }. log $ {name }. $ {YESTERDAY }. log # Send the USR1 signal to the nginx main process, and the USR1 signal re-opens the log file # Otherwise, the nginx main process will write or move the log file # three methods, use any one of the following methods as needed: # service nginx reload # kill-USR1 $ (cat $ PID) $ NGINX-s reload tar zcf restart name1_.##yesterday#.log.gz $ {name }. $ {YESTERDAY }. log rm-rf $ {name }. $ {YESTERDAY }. log} # cyclically split log for (I = 0; I <$ server_count; I ++); do cut_logs $ {server_names [$ I]} done