Apache Log Split Script

Source: Internet
Author: User

"Generating Background"

As the company's NTP Center server access is growing, access logs are increasing, the original log is not cut, a single log is too large (the largest 3.7G), if the clean up disk space will delete the entire access log, which will lose a lot of important information, Therefore, it is necessary to cut logs so that if you have too many files in the future, you can delete the history files.


Script


#!/bin/bashyesterday=$ (date-d yesterday +%y%m%d) gzip= "gzip-c" log_file= "/etc/httpd/logs/access_ntp.log" LOG_BACKUP _file= "/etc/httpd/logs/access_ntp_backup/access_ntp_${yesterday}.log.gz" $GZIP ${log_file} > ${LOG_BACKUP_FILE} >${log_file}


Add a script to cron

echo "0 0 * * */bin/sh/scripts/rotate_access_log.sh &>/dev/null" >>/var/spool/cron/root

Daily 0:0 generate a compressed log file in the/etc/httpd/logs/access_ntp_backup directory, as in the form of access_ntp_20160514.log.gz


Apache Log Split 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.