按日期分割nginx日誌

Ihc_Gnahz發表於2018-04-24

廢話不多說,直接上指令碼

cutlog.sh

#!/bin/bash -x
#your work space
WORKSPACE=/work
LOGS_PATH=${WORKSPACE}/logs

TODAY=$(date -d 'today' +%Y-%m-%d)

mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${TODAY}.log

PID_PATH=${WORKSPACE}/logs/nginx.pid

kill -USR1 $(cat ${PID_PATH})
複製程式碼

部署指令碼中新增如下程式碼,把cutlog.sh加入定時任務

deploy.sh

.
.
echo "1 0 * * * root sh $WORKSPACE/cutlog.sh >> $WORKSPACE/cutlog.log 2>&1" > /etc/cron.d/cut_log
複製程式碼

各命令就不一一解釋了,不明確的請在評論中回覆

相關文章