Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to cut logs in Nginx script

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to cut the log with Nginx script", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to cut the log with Nginx script" this article.

#! / bin/bash

# log log directory of Nginx

Log_path='/opt/app/nginx/logs/'

# Nginx's pid file storage directory

Pid_path= "${log_path} nginx.pid"

# clear the logs before the specified date

DAYS=60

# generate yesterday's log file

# if you specify date-d "10 day ago 2017-06-08" +% Y-%m-%d 10 days ago

Mv ${log_path} access.log ${log_path} access_$ (date-d "yesterday" + "% Y%m%d") .log

Mv ${log_path} error.log ${log_path} error_$ (date-d "yesterday" + "% Y%m%d") .log

Kill-USR1 `cat ${pid_path} `

# folder size conversion to M

# File size defaults to bytes

Size= `du-b ${log_path} | awk'{print int ($1ax 1024)}'`

# Delete files from 60 days ago

If ["$size"-gt "1000"]; then

# find corresponding directory-mtime + days-type f-name "file name"-exec rm-rf {}\

Find ${log_path}-mtime + $DAYS-type f-name "* .log"-exec rm-rf {}\

Fi

# here is the task plan

[root@centos7 ~] # cat / var/spool/cron/root

SHELL=/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Export PATH

0 * / bin/sh / opt/log_backup.sh

# Grant permissions

Chmod + x / opt/log_backup.sh

The above is all the content of the article "how to cut the log with Nginx script". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report