日志切割实例
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 {} \;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。