1. 切割日志的脚本
#!/bin/bash
logs_path=”/usr/local/nginx/logs”
log_name=”access.log”
pid_path=”/usr/local/nginx/logs/nginx.pid”
YESTERDAY=$(date -d “yesterday” +%Y-%m-%d)
mv ${logs_path}/${log_name} ${logs_path}/access-${YESTERDAY}.log
kill -USR1 `ps axu | grep “nginx: master process” | grep -v grep | awk ‘{print $2}’`
find ${logs_path} -mtime +7 -name “*.log” | xargs rm -f
exit 0
2. 定时任务配置
0 0 * * * root /bin/sh /usr/local/nginx/logs/cut_nginx_log.sh
发表评论