nginx日志按天分割


#!/bin/bash  
#Rotate the Nginx logs to prevent a single logfile from consuming too much disk space.   
LOGS_PATH=/data/logs/nginx
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
cd /data/logs/nginx/
ACCESS_FILE_LIST=`ls *_access.log`
ERROR_FILE_LIST=`ls *_error.log`
for ACCESS_FILE in ${ACCESS_FILE_LIST[*]}
 do
 mv ${LOGS_PATH}/${ACCESS_FILE} ${LOGS_PATH}/${ACCESS_FILE}${YESTERDAY}.log
done

for ERROR_FILE in ${ERROR_FILE_LIST[*]}
 do
 mv ${LOGS_PATH}/${ERROR_FILE} ${LOGS_PATH}/${ERROR_FILE}${YESTERDAY}.log
done

## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件  
kill -USR1 $(cat /data/nginx/logs/nginx.pid)
 

你可能感兴趣的:(nginx日志按天分割)