How to cut logs in Nginx script
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!