日志切割实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日志切割实例相关的知识,希望对你有一定的参考价值。
日志切割实例
1、任务计划收切割和删除日志的计划
#tracking & cookiemapping #*/10 * * * * bash /usr/local/zamplus-luanx-server/bin/log_rotate.sh #5 0 * * * bash /usr/local/zamplus-luanx-server/bin/log_clean.sh
2、log_rotate.sh 切割日志,日志由nginx产生
[email protected]:/usr/local/LuanxServer/Luanx-shells# vim /usr/local/LuanxServer/Luanx-shells/log_rotate.sh #!/bin/bash _prefix="/usr/local/LuanxServer" _log_tracking_statistic_dir="/data/tracking/statistic" _log_cm_statistic_dir="/data/cm/statistic" if [ ! -d ${_log_tracking_statistic_dir} ]; then mkdir -p ${_log_tracking_statistic_dir}; fi if [ ! -d ${_log_cm_statistic_dir} ]; then mkdir -p ${_log_cm_statistic_dir}; fi time=`date +%Y%m%d%H%M` mv ${_prefix}/logs/tracking_site.log ${_log_tracking_statistic_dir}/track-s-${time}.log mv ${_prefix}/logs/tracking_promote.log ${_log_tracking_statistic_dir}/track-p-${time}.log mv ${_prefix}/logs/tracking_mob.log ${_log_tracking_statistic_dir}/track-m-${time}.log mv ${_prefix}/logs/tracking_conversion.log ${_log_tracking_statistic_dir}/track-c-${time}.log mv ${_prefix}/logs/cm.log ${_log_cm_statistic_dir}/cm-s-${time}.log kill -USR1 `cat ${_prefix}/logs/nginx.pid`
3、log_clean.sh 删除超过15天的日志
[email protected]:/usr/local/LuanxServer/Luanx-shells# vim /usr/local/LuanxServer/Luanx-shells/log_clean.sh #!/bin/bash _log_tracking_statistic_dir="/data/tracking/statistic" _log_cm_statistic_dir="/data/cm/statistic" if [ ! -d ${_log_tracking_statistic_dir} ]; then exit; fi find ${_log_tracking_statistic_dir}/ -type f -mtime +15 -name "*.log" -exec rm -rf {} \; if [ ! -d ${_log_cm_statistic_dir} ]; then exit; fi find ${_log_cm_statistic_dir}/ -type f -mtime +15 -name "*.log" -exec rm -rf {} \;
本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1887435
以上是关于日志切割实例的主要内容,如果未能解决你的问题,请参考以下文章