分类:运维 发布时间:2018-07-09 17:06:00
### 思路 1、编写脚本,每天复制一份访问日志,并按日期重命名 2、删除原本日志,方便记录新的日志 3、定期删除一段时间前访问日志 ### 编写脚本 新建脚本 nginx_log_of_yesterday.sh,保存在/home/sh目录下(可自行修改) ``` #!/bin/bash # program: # cut nginx log of yesterday source /etc/profile log_path="/home/wwwlogs/" yesterday=$(date -d "yesterday" +"%Y%m%d") mv ${log_path}access.log ${log_path}access.$yesterday.log nginx -s reload find /home/wwwlogs/ -mtime +7 -name "*.log" -exec rm -rf {} \; ``` 写好后可以先直接执行一次,查看是否有异常 ### 添加定时任务 ``` 0 0 * * * /bin/bash /home/sh/nginx_log_of_yesterday.sh ``` ### 重启定时任务 这里注意下 sh 文件需要有可执行权限
搜索
文章分类
最新文章