Nginx timed task complete log cut

Source: Internet
Author: User

One: Nginx log cutting
(1) Create a new data directory
[Email protected] nginx]# Mkdir/data
(2) Create a new shell script
[Email protected] data]# VI runlog.sh
(3) Writing shell scripts

#需要切割日志文件的路径

Logpath=/usr/local/nginx/logs/access.log

#根据月份创建一个目录

basepath=/data/$ (date-d yesterday +%y%m)

Mkdir-p $BASEPATH

The number of days #把当前的日志文件修改 the current date

bak= $BASEPATH/$ (date-d yesterday +%y%m%d%h%m). Hgj123.com.log

MV $LOGPATH $bak

#重新创建一个日志文件

Touch $LOGPATH

#重新执行nginx the volume of the signal reread the log [note the anti-quote]

KILL-USR1 ' Cat/usr/local/nginx/logs/nginx.pid '

(3) Implementation

SH runlog.sh

(4) Scheduled Tasks

Crontab-e

#编写代码

*/1 * * * * SH data/runlog.sh

/* Note points

* * * */xxx/path/b.sh daily 0:1 (recommended between 02-04 points, system load is small)

*/

Nginx timed task complete log cut

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.