系统:centos7
nginx:编译安装1.16.1
创建定时任务
[root@nginx1 shell]# crontab -l
0 1 * * * /root/shell/cut_log.sh
编写脚本
[root@nginx1 shell]# cat cut_log.sh
#!/bin/bash
#日志路径
logs_path="/usr/local/nginx/logs/"
#删除过期的文件
find $logs_path -mtime +30 -name "access_*.log" -exec rm -f {} ;
#获取nginx进程pid
nginx_pid="/usr/local/nginx/logs/nginx.pid"
/usr/bin/mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d").log
#重新打开日志文件
kill -USR1 `cat ${nginx_pid}`
查看效果