首页 > 代码库 > 日志切割实例
日志切割实例
日志切割实例
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
日志切割实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。