nginx分割日志,多日志循环处理
原来网上也有很多nginx分割日志的方法,发现都是针对access和error两个日志,今天完善一下,多项目多日志循环处理。
vim /data/script/cut_nginx_log.sh
#!/bin/bash
# This script run at 00:00
DATA_TIME=$(date +%F-%H:%M:%S)
# The Nginx logs path
nginx_log="/data/logs/nginx"
# Backup logs path
logs_path="/data/logs/cut_nginx_logs"
pid=$(cat /data/server/nginx/nginx.pid)
[ -d $logs_path ] || mkdir -p $logs_path
for f in $(find $nginx_log/ -type f);
do
echo ${f} > /tmp/tmp_log_name.txt
mv ${f} ${logs_path}/$(awk -F"/" '{print $NF}' $(echo /tmp/tmp_log_name.txt))_${DATA_TIME}.log;
done
kill -USR1 ${pid}
然后加入计划任务
crontab -e
00 00 * bash /data/script/cut_nginx_log.sh
相关推荐
nginxs 2020-11-14
Guanjs0 2020-11-13
小木兮子 2020-11-11
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09
mqfcu 2020-11-10
windle 2020-10-29