Linux nginx or tomcat log split

Source: Internet
Author: User

Nginx log is not automatic segmentation according to the date, the feeling will be a problem, so I intend to split the log, in the Internet to find the next, feel very troublesome, to split the log, and then also from the Kai PID, should be good use it, I did not test. It feels too troublesome. I wrote one according to the idea. Also very useful. For everyone's reference.


#!/bin/bash

# The Nginx logs path

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

Cp/home/log/nginx/logs/access.log/home/log/nginx/logs/access.log. $yesterday

Cat/dev/null >/home/log/nginx/logs/access.log


Note ' This symbol is not a single quote, it is the symbol in front of the number 1.

Idea: The first step is to copy the log for yesterday's log, and the second to empty the log. Done. Good understanding.


stored as SH file, and then added to the crontab inside, just fine. Run every morning.

The command crontab-e enters edit mode and writes the following content. Just fine.


XX * * * */bin/sh/home/sh/cutnginxlog.sh


Run for many days, the effect is good. Hope to be of help to you.


This article is from the "Wu Bin Technical Record" blog, please make sure to keep this source http://bingowu.blog.51cto.com/2758460/1882946

Linux nginx or tomcat log split

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.