本文共 615 字,大约阅读时间需要 2 分钟。
一个nginx切割日志的脚本,自动删除7天前日志
#!/bin/bash LOGS_PATH=/home/wwwlogs YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
kill -USR1 ps axu | grep "nginx: master process" | grep -v grep | awk '{print $2}'
gzip -9 ${LOGS_PATH}/access_${YESTERDAY}.log
cd ${LOGS_PATH}
find . -mtime +7 -name "201-9" | xargs rm -fexit 0 可以通过grep、awk找到nginx master也可以直接kill -USR1 pidkill -USR1 ps aux | grep "nginx: master process" | grep -v grep | awk '{print $2}'或
kill -USR1 cat /usr/local/nginx/logs/nginx.pid
转载地址:http://kefsa.baihongyu.com/