Shell cutting Nginx Log tool for five days without restarting Nginx

Source: Internet
Author: User

Ideas:

1, back up yesterday's log, while deleting the five days before the backup data.

2, copy the log file, and set the original log file is empty

Shell

#!/bin/bash
#function: Cut nginx log files
#author Kung

log_path= '/home/wwwlogs/' log_bak_path= '
/ home/wwwlogs_bak/'
date_yesterday=$ (date-d "Yesterday" + "%y-%m-%d")
del_date=$ (date-d "$date _yesterday 5 Day ago "+"%y-%m-%d ")

mkdir-p ${log_bak_path}${date_yesterday} for

file in ' ls ${log_path} '
do
        CP ${ Log_path}${file} ${log_bak_path}${date_yesterday}
        echo ' > ${log_path}${file} done

if [-D ${log_ Bak_path}${del_date}]
then
        rm-rf ${log_bak_path}${del_date}
fi

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.