标签:日志切割实例
日志切割实例
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产生
root@TS02:/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天的日志
root@02:/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
标签:日志切割实例
原文地址:http://daixuan.blog.51cto.com/5426657/1887435