The Linux nginx log segmentation

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
#This method is suitable for every generated log files are large, if the log file is not big, but the execution time to modify the script.
#The current nginx server access log directory
#Storage path log after segmentation
#According to the date creating the directory
date_path="$new_log_path$(date +"%Y" -d "-1 days" )/$(date +"%m" -d "-1 days")"
mkdir -p "$date_path"
#The current mobile nginx log file to the specified directory
mv ${logs_path}access.log ${date_path}/access_$(date -d "-1 days" +"%Y%m%d").log
#Restart nginx to generate the log file
service nginx restart

Note: this script every server selection pressure than hours can be executed.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Betty at March 10, 2014 - 5:34 AM