Nginx log splitting script and nginx log splitting script

Source: Internet
Author: User

Nginx log splitting script and nginx log splitting script
#! /Bin/bash
#01 00 ***/nginxlogs/ngx_logcut.sh>/dev/null 2> & 1 # the script can be automatically executed in a scheduled task.

Pidfile =/var/run/nginx. pid # nginx process pid File

Logpath = '/nginxlogs/' # log directory

Keepdays = 30 # Log Retention days

Logfiles = (error. log access. log) # list log names in Arrays

Cd $ logpath # enter the log directory

For logfile in $ {logfiles [@]}; do # Matches in array form
If [! -E $ logfile];
Then
Continue
Fi
Find.-type f-name $ logfile "20 *"-mtime + $ keepdays-exec rm {}\; # find the matching log and delete it
Mv $ logfile $ (date-d "yesterday" + "% Y % m % d") # change yesterday's log to log name + date Format
Done


Kill-USR1 'cat $ pidfile' # USR1 is usually used to inform the application to reload the configuration file. For example, if the nginx server sends a USR1 signal, the following steps will occur: stop accepting new connections, wait for the current connection to stop, re-load the configuration file, re-open the log file, restart the server, so as to achieve relatively smooth changes without shutting down

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.