日志切割实例
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};fiif [ ! -d ${_log_cm_statistic_dir} ]; then mkdir -p ${_log_cm_statistic_dir};fitime=`date +%Y%m%d%H%M`mv ${_prefix}/logs/tracking_site.log ${_log_tracking_statistic_dir}/track-s-${time}.logmv ${_prefix}/logs/tracking_promote.log ${_log_tracking_statistic_dir}/track-p-${time}.logmv ${_prefix}/logs/tracking_mob.log ${_log_tracking_statistic_dir}/track-m-${time}.logmv ${_prefix}/logs/tracking_conversion.log ${_log_tracking_statistic_dir}/track-c-${time}.logmv ${_prefix}/logs/cm.log ${_log_cm_statistic_dir}/cm-s-${time}.logkill -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;fifind ${_log_tracking_statistic_dir}/ -type f -mtime +15 -name "*.log" -exec rm -rf {} \;if [ ! -d ${_log_cm_statistic_dir} ]; then exit;fifind ${_log_cm_statistic_dir}/ -type f -mtime +15 -name "*.log" -exec rm -rf {} \;