首页 > 代码库 > 日志文件清理代码
日志文件清理代码
对于产生大量日志的服务器,要对日志进行控制,如果任由日志膨胀可能会写满磁盘造成服务器宕机。
#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
日志文件清理代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。