nginx日誌分割指令碼

2022-08-04 23:09:19 字數 1323 閱讀 1536

此文件只針對linux分割nginx日誌

nginx日誌不自動帶日誌分割功能,需要自己寫指令碼分割日誌,並加入到每日任務中,定期分割、儲存、刪除日誌

此指令碼包括,日誌分割、儲存、刪除、重建日誌檔案

#!/bin/bash

#date +%y%m%d%h%m%s

year=`date +%y`

month=`date +%m`

day=`date +%d`

hour=`date +%h`

minute=`date +%m`

second=`date +%s`

#pid path

pid_path="

/portal/software/nginx/logs/nginx.pid

"#log path

logdir=/portal/software/nginx/logs/back_up_log/logdir2=/portal/software/nginx/logs/sotp_error_log/# screening log files

logname=`ls /portal/software/nginx/logs/ |grep

"\.log"`

#create the logdir

#mkdir -p $logdir1

#mkdir -p $logdir2

#move the log

file

to new position, and change the name

for i in$do

#log name

logfile=$-$year"

-"$month"

-"$day"-"

$hour$minute$second

mv -f /portal/software/nginx/logs/$i $/$ && touch /portal/software/nginx/logs/$i

done

# reload nginx process

kill -usr1 `cat

$`# remove logs

6days ago

/usr/bin/find $logdir -name "

*" -mtime +6 | /usr/bin/xargs

rm -f

加入日常任務

crontab -e

00 01 * * * /bin/sh /opt/cronjob/mysql_daily_backup.sh

儲存後,重啟crond任務

/etc/init.d/crond restart

nginx日誌分割小指令碼

nginx的日誌一直是寫在乙個檔案上面,執行久了之後檔案會非常大,因此我們有必要對nginx的日誌進行分割 12 3456 78910 11 bin bash access log data nginx www.log error log data nginx error.log yesterday...

Nginx 日誌自動分割指令碼

1 分割指令碼 cut nginx logs.sh bin bash cut nginx logs.sh author xingxiudong set the path to nginx log files log files path var log nginx set nginx log fil...

nginx日誌分割和定時清理指令碼

首先是日誌定時分割指令碼 bin sh dat date y m d mon date y m echo dat mondir usr openresty logs mon bin echo mondir usr openrest hello.info if x mondir then echo 開...