nginx日志切割脚本

#!/bin/bash
##午夜执行

LOGS_PATH=/var/log/nginx
#FTP_LOG_PATH=/ftp/log/lb_log
YESTERDAY=$(date -d last-day +%Y-%m-%d)

mv ${LOGS_PATH}/ld.log ${LOGS_PATH}/ld.log-${YESTERDAY}
kill -USR1 $(cat /var/run/nginx.pid)
awk -F ‘”‘ ‘/amax.php/{print $4}’ ${LOGS_PATH}/ld.log-${YESTERDAY} >${LOGS_PATH}/rqbody.log-${YESTERDAY} 2>${LOGS_PATH}/request_body/rqerror.log

gzip -c ${LOGS_PATH}/rqbody.log-${YESTERDAY} > ${LOGS_PATH}/request_body/rqbody.log-${YESTERDAY}.gz
rm -fr ${LOGS_PATH}/rqbody.log-${YESTERDAY}
rm -fr ${LOGS_PATH}/ld.log-${YESTERDAY}

find /var/log/nginx/ -mtime +7 -name “*.log” -exec rm -fr {} \;

发表评论

电子邮件地址不会被公开。