-
需求
nginx的日志文件路径
每天0点对nginx 的access与error日志进行切割
以前一天的日期为命名 -
脚本
#!/bin/bash
#Auto cut nginx log script.
#create by vincent
#create date:2019-10-12
#nginx日志路径
logs_path=/usr/local/nginx/logs
YesterDay=$(date -d 'yesterday' +%Y-%m-%d)
#移动日志并以日期改名
mv ${logs_path}/access.log ${logs_path}/access_${YesterDay}.log
mv ${logs_path}/error.log ${logs_path}/error_${YesterDay}.log
#向nginx主进程发送信号,重新生成日志文件
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
- 定时器执行配置
0 0 * * * /home/nginxLog/nginx_access_log.sh
网友评论