Implement methods to automatically delete Nginx logs periodically _nginx

Source: Internet
Author: User

The system log is a very important thing but at the same time if we do not regularly clear the space will be to the log, I would like to introduce a regular delete log implementation methods, you can refer to the students.

Nginx's log files accumulate too much and finally fill up the entire disk space, so yesterday a script that can be automatically deleted on a regular basis.

#!/bin/bash
find/usr/local/nginx/logs/-mtime +15-type f-name *.log | Xargs rm-f


The above script is to delete the log files from the 15 days before nginxlogs, and you can refer to the above script to delete the log files of other programs, such as PHP and Tomcat. However, the use of the script will need to nginx log files to automatically split, otherwise it will delete the log file is being written, Nginx log segmentation script can see the Linux source mode installation nginx and PHP (FastCGI) or CentOS system initial installation MySQL, PHP and Nginx scripts.

To save the script and use the chmod +x command to specify executable permissions, it is best to join the task list (performed one o'clock in the morning every day):

[Root@localhost ~]# crontab-e * *
/bin/bash/root/shell/autodellogs.sh
[root@localhost ~]# service Crond Restart 

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.