One shell per day (eight) Nginx log cutting

Source: Internet
Author: User

Nginx log will increase with the amount of traffic, the larger log will affect the analysis log when the analysis and processing, we can use the shell to the Nginx log timing segmentation, to weeks or days, for a long time log can be deleted periodically, reduce disk waste

Code:

# cat logrotate.sh #!/bin/bash#rotate nginx logs#writen by AikerPATH=$PATH://usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/binlogs_path=/var/log/nginxd=$(date -d "-1 day" +%F)mv $logs_path/access.log $logs_path/access_${d}.logmv $logs_path/error.log $logs_path/error_${d}.log#向nginx主进程发送USR1信号重新打开日志文件kill -USR1 $(cat /var/run/nginx.pid)

Timed cut logs:
Crontab-e

0 0 * * 0 /root/script/logrotate.sh > /dev/null 2>&1
# ll /var/log/nginx/                         total 64-rw-r--r-- 1 nginx root  3205 Feb 12 11:42 access_2018-02-11.log-rw-r--r-- 1 nginx root 41951 Feb 12 11:53 access.log-rw-r--r-- 1 nginx root 14441 Feb  9 10:12 error_2018-02-11.log-rw-r--r-- 1 nginx root     0 Feb 12 11:43 error.log

One shell per day (eight) Nginx log cutting

Related Article

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.