标签:linux
apache切割工具: cronlog 和rotare等日志切割工具
nginx切割工具有: nginx cron+x scripts
[root@web01 ~]# mkdir -p /server/scripts [root@web01 ~]# cd /server/scripts/ [root@web01 scripts]# vim cut_nginx_log.sh #vim输入如下内容 cd /application/nginx/logs /bin/mv access.log access_$(date +%F).log /application/nginx/sbin/nginx -s reload
[root@web01 logs]# /bin/sh /server/scripts/cut_nginx_log.sh [root@web01 scripts]# ls /application/nginx/logs/ access.log error.log nginx.pid access_2017-08-21.log [root@web01 scripts]# date -s "2016/05/14" #设定现在时间为20160514 Sat May 14 00:00:00 CST 2016 [root@web01 scripts]# /bin/sh /server/scripts/cut_nginx_log.sh [root@web01 scripts]# ls /application/nginx/logs/ access_2016-05-14.log access.log nginx.pid access_2017-08-21.log error.log www_access_2017-08-21.log
继续优化切割脚本
[root@web01 scripts]# vim cut_nginx_log.sh cd /application/nginx/logs /bin/mv access.log access_$(date +%F).log /application/nginx/sbin/nginx -s reload # rsync .....to backup server #del date before 7 day find ...
设置定时任务:每天00:00切换日志
[root@web01 scripts]# crontab -e [root@web01 scripts]# crontab -l #time sync by oldboy at 2010-2-1 */5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1 #backup 00 00 * * * /bin/bash /server/scripts/backup.sh &>/dev/null ######cut_nginx_log##### 00 00 * * * /bin/sh /server/scripts/cut_nginx_log.sh>/dev/null 2>&1 ##这个就是切割日志
上述脚本时间可以写成access_$(date %F -d ‘-1day‘).log ##就是当前日志-1天意思
本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1958181
标签:linux
原文地址:http://sandshell.blog.51cto.com/9055959/1958181