Apache Log cut shell script

Source: Internet
Author: User

Apache, Nginx and other Web server log volume is huge, if not cut will lead to log files too large, not easy to clean up, and to log analysis collection work caused trouble. The following example is Apache log cutting script, Nginx and other Web services are also applicable


Code:

#! /bin/bash

Apache_log_path= "/usr/local/apache/logs" #指定日志存储位置

Log_filenames= '/bin/ls $apache _log_path '

Save_days=7 #定义保留7天内日志

#按照日期时间存储日志

/BIN/MV $apache _log_path/access_log $apache _log_path/access_log_ ' date +%f '. Log

/usr/local/apache/bin/apachectl-k Graceful #重新加载服务

# Find log files up to 7 days ago and delete

find$apache_log_path -mtime +$save_days -exec rm-rf {} \;



ok,将脚本放到crontab定时执行就Ok了,其他web软件同样适用。注意日志文件重命名后需要重新加载服务,否则造成异常

Apache Log cut shell script

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.