码迷,mamicode.com
首页 > 其他好文 > 详细

日志文件清理代码

时间:2017-04-27 17:03:10      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:change   color   date   span   膨胀   mint   app   cat   tor   

对于产生大量日志的服务器,要对日志进行控制,如果任由日志膨胀可能会写满磁盘造成服务器宕机。

#code by ls in 20170427
date_now=`date +"%Y-%m-%d"`
date_yes=date -d "1 day ago" +"%Y-%m-%d"
#the drectory of this script,need to change for yourself
clean_log_path="/iom_jk/IOM_INF/tomcat_6.0.44_1/clean_log/"
if ! [ -e ${clean_log_path} ]
then
    mkdir -p $clean_log_path
fi
clean_log_file="${clean_log_path}clean_log.log" #the logfile of this script,need to change for yourself
delete_log_prefix="log.log."            #the prefix of delete file,need to change for yourself
zero_log_postfix=".log"                        #the postfix of zero file,neet to change for yourself
#those drectory that need to clean,neet to change for yourself
array_path[0]="/iom_jk/IOM_INF/tomcat_6.0.44_1/webapps/IomInterface/WEB-INF/sh/logs"
array_path[1]="/iom_jk/IOM_INF/tomcat_6.0.44_1/bin/logs"
array_path[2]="/iom_jk/app/interface/IomInterface/WEB-INF/sh/logs"

delete_log_file()            #the function to delete yesterday log file,do not need to change in general
{
    if [ -e ${delete_log_prefix}${date_yes} ]
    then
        rm -f ${delete_log_prefix}${date_yes} && echo "${data_now} : ${delete_log_prefix}${date_yes} have been delete" >> ${clean_log_file}
    fi
}

zero_log_file()       #the function to zero log file,do not need to change in general
{
    for file_name in `ls *${zero_log_postfix}`
    do
        echo "" > ${file_name} && echo "${data_now} : ${file_name} have been clean" >> ${clean_log_file}
    done
}

for path_log in $array_path[*]
do
    cd $path_log
    echo "$date_now : enter ${path_log}" >> ${clean_log_file}
    delete_log_file                            #the function to delete yesterday log file,need to change for yourself
    zero_log_file                                #the function to zero log file,need to change for yourself
    echo "" >> ${clean_log_file}
done

 

日志文件清理代码

标签:change   color   date   span   膨胀   mint   app   cat   tor   

原文地址:http://www.cnblogs.com/lsdb/p/6775078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!