Nginx Log Cutting

Source: Internet
Author: User

1.nginx_log_rotate.sh file

#nginx Log Cut script

#author: Henrylinux

#!/bin/bash

#1. set the log file storage directory, assuming that your Nginx The log exists in this directory

Logs_path= "/data/logs/nginx/"

#2. Set PID file, this according to your own environment, find Nginx.pid Location Directory

Pid_path= "/usr/local/nginx/logs/nginx.pid"

#3. Create a date file directory for split storage

Datetime= ' date-d "Yesterday" + "%y%m%d";

New_log_path= $logs _path$datetimemkdir-p $new _log_path

#4. move all log files in this directory by date

Log_file_list= ' ls-l $logs _path '; for log_file in $log _file_list;do

Log_file_name= $logs _path$log_file;

If [-f $log _file_name];

Then

MV $log _file_name $new _log_path;

Fidone

#5. to Nginx main process signal reopen log kill-usr1 ' Cat ${pid_path} '

2. Set up Scheduled Tasks

0 0 * * */data/sh/nginx_log_rotate.sh

Nginx Log Cutting

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.