Nginx的定時切割日誌腳本

1. 建立腳本/application/nginx/sbin/cut_nginx_log.sh
2.  vi /opt/nginx/logs/cut_nginx_log.sh
#!/bin/bash
#author:ley
#date:2014-12-15
#content:cutthe nginx's log at 00:00
#email:xxx@qq.com
#qq:xxxx
logs_path="/opt/nginx/logs/"
mkdir-p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d"yesterday" +"%m")/
mv${logs_path}access.log ${logs_path}$(date -d "yesterday"+"%Y")/$(date -d "yesterday" +"%m")/access_$(date-d "yesterday" +"%Y%m%d").log
kill-USR1 `cat /opt/nginx/logs/nginx.pid`
4.crontab -e
00 00 * * * /bin/bash  /opt/nginx/logs/cut_nginx_log.sh

方法二:
[root@Liangenyulogs]# mv www.access.log www.access_$(date +%F -d -1day).log
[root@Liangenyulogs]# /application/nginx/sbin/nginx -s reload
#編寫腳本
[root@Liangenyulogs]# vim cut.nginx.log
cd/application/nginx/logs && \
/bin/mvwww.access.log www.access_$(date +%F -d -1day).log
/application/nginx/sbin/nginx-s reload
#添加到定時任務
30 19 * * * /bin/sh cut.nginx.log >/dev/null 2>&1
相關文章
相關標籤/搜索