Created
August 15, 2018 03:41
-
-
Save zhangludi/ff1bcb1e8571772155cd21bd0f8afe46 to your computer and use it in GitHub Desktop.
centos,nginx log log 定时器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#step1:加脚本 cut_nginx_log.sh,主进程把USR1信号发给worker,worker接到这个信号后,会重新打开日志文件 | |
#!/bin/bash | |
logs_path="/usr/local/nginx-1.6.0/logs" | |
log_name="access.log" | |
pid_path="/usr/local/nginx-1.6.0/logs/nginx.pid" | |
mv ${logs_path}/${log_name} ${logs_path}/"access-"$(date --date="LAST DAY" "+%Y-%m-%d").log | |
kill -USR1 `cat ${pid_path}` | |
#find ${logs_path} -name "*.log" -mtime +30 -delete | |
#step2:crontab 定时跑脚本,每天0点0分执行脚本 | |
crontab -e | |
0 0 * * * /usr/local/nginx-1.6.0/logs/cut_nginx_log.sh | |
链接:https://www.jianshu.com/p/9b146a5834c1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment