删除Ngnix日志的脚本
#!/bin/bash #初始化 LOGS_PATH=$(pwd)/logs YESTERDAY=$(date -d "yesterday" +%Y-%m-%d) #按天切割日志 mv ${LOGS_PATH}/access_log ${LOGS_PATH}/access_${YESTERDAY}_log #向 Nginx 主进程发送 USR1 信号,重新打开日志文件,否则会继续往mv后的文件写内容,导致切割失败. kill -USR1 `ps axu | grep "nginx: master process" | grep -v grep | awk ‘{print $2}‘` #删除7天前的日志 cd ${LOGS_PATH} find . -mtime +7 -name "*20[1-9][3-9]*" | xargs rm -f exit 0
时间: 2024-10-01 00:51:31