#!/bin/bash
# 设置日志文件存放目录
logs_path="/zhonghong/nginx_log/"
# 设置pid文件
pid_path="/usr/local/nginx/logs/nginx.pid"
# 重命名日志文件
mv ${logs_path}/access.log ${logs_path}/access_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
mv ${logs_path}/error.log ${logs_path}/error_$(date -d "yesterday" +"%Y%m%d%H%M%S").log
# 向nginx主进程发信号重新打开日志
kill -USR1 `cat ${pid_path}`
# 删除超过指定时间的日志文件,单位:天
find $backup_path -name "*.log" -type f -mtime +30 -exec rm -rf {} \;