时间:2022-05-03 10:57:06 | 栏目:Nginx | 点击:次
环境说明:
操作系统CentOS7.0,默认在线安装nginx。
nginx配置文件路径:/etc/nginx/nignx.conf,
nginx日志文件路径:/var/log/nginx/access.log
nignx.pid路径:/run/nginx.pid
新建的定时脚本位置/shell/nginx/logs.sh
1.新建脚本并执行
#mkdir /shell/nignx #cd /shell/nginx #vim logs.sh
#!/bin/bash base_path='/var/log/nginx' log_path=$(date -d yesterday +"%Y%m") day=$(date -d yesterday +"%Y%m%d") mkdir-p$base_path/$log_path mv$base_path/access.log $base_path/$log_path/access_$day.log #echo $base_path/$log_path/access_$day.log kill-USR1`cat /run/nginx.pid`
#chmod a+X #./logs.sh
2.定时执行(每天0点)
#crontab -e #0 0 * * * /bin/bash /shell/nginx/logs.sh #wq
总结