cutnginxlog.sh -Nginx 日志文件切割和定时执行

#!/bin/sh
# Program:
# Auto cut nginx log script.

# nginx日志路径
LOGS_PATH=/usr/local/nginx/logs
TODAY=$(date -d ‘today’ +%Y-%m-%d)

# 移动日志并改名
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${TODAY}.log
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${TODAY}.log
#zip -m ${LOGS_PATH}/error_${TODAY}.log.zip ${LOGS_PATH}/error_${TODAY}.log
#zip -m ${LOGS_PATH}/access_${TODAY}.log.zip ${LOGS_PATH}/access_${TODAY}.log
tar -czf ${LOGS_PATH}/error_${TODAY}.log.tar.gz ${LOGS_PATH}/error_${TODAY}.log –remove-files
tar -czf ${LOGS_PATH}/access_${TODAY}.log.tar.gz ${LOGS_PATH}/access_${TODAY}.log –remove-files

# 向nginx主进程发送重新打开日志文件的信号
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)

#echo ‘0 0 * * * root /usr/local/nginx/cutnginxlog.sh >> /usr/local/nginx/logs/cutnginxlog.log 2>&1’ >> /etc/crontab

#crontab -e

留下评论