An nginx log switch script

Source: Internet
Author: User
An nginx log switch script-Linux Enterprise Application-Linux server application information. For more information, see the following section. The disk space was cleared two days ago and it was found that nginx logs occupied a large amount of space;
[Root @ server219 logs] # ll-h
Total 6.8 GB
-Rw-r -- 1 root 5.4G 07-29 10:36 access. log
-Rw-r -- 1 root 1.4G 07-29 10:32 error. log
At this time, I felt speechless, so I wrote an nginx log switching script.
###### Script environment ######
#! /Bin/bashi
###### Log Path ####
LOGS_PATH =/usr/local/nginx/logs
####### Date of the previous day ####
YESTERDAY = $ (date-d "yesterday" '+ % Y-% m-% D ')
####### Move a file ####
Mv $ {LOGS_PATH}/access. log $ {LOGS_PATH}/access. $ {YESTERDAY}. log
####### Restart the service for the newly created access. log ### effective ###
Kill-HUP 'cat $ {LOGS_PATH}/nginx. Pi'
In this case, the nginx service will be stopped, which should be measured according to the company's actual environment ..... If you stop, we recommend that you wait for the early morning ....

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.