Nginx splits logs by day, and nginx splits logs

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.