码迷,mamicode.com
首页 > 系统相关 > 详细

linux的定时删除备份及删除文件后无法释放资源的脚本内容

时间:2019-08-15 15:52:48      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:auto   echo   linu   rm -rf   time   grep   脚本   logs   deploy   

#!/bin/bash  
#clearLog.sh  

tomcatDir=/usr/local/tomcat8-rcc-api/autoDeploy/*;
tomcatDir2=/usr/local/tomcat8-rcc-api/logs/*;
tomcatDir3=/usr/local/tomcat8-rcc-api-7000/logs/*;
tomcatDir4=/usr/local/tomcat8-rcc-api-7000/autoDeploy/*;

devInfo=($(df -l | awk ‘{print $1}‘))     #日志所处的磁盘  
perInfo=($(df -l | awk ‘{print int($5)}‘)) #磁盘使用率  
  
  	find $tomcatDir2 -mtime +30 -name "*.log" -exec rm -rf {} \;
	find $tomcatDir3 -mtime +30 -name "*.log" -exec rm -rf {} \;
	lsof | grep deleted | awk ‘{print $2}‘ | xargs -I {} kill -9 {}
	
	
for i in `seq 0 ${#perInfo[@]}`;  
do   
   if [[ ${devInfo[i]} = ‘/dev/vda1‘ ]] && [[ ${perInfo[i]} -ge 76 ]];  
   then  
        
     for file in $tomcatDir2;  
     do  
         exist=`echo $file | awk ‘{if(match($0,/\.log/)) print "yes"}‘`;
		 exist2=`echo $file | awk ‘{if(match($0,/\.out/)) print "yes"}‘`;		 
         if [[ -f $file ]] && [[ ${exist} = yes ]];  
         then  
           echo ‘‘ > $file;  
           echo $(date) $file "clear log ok!" >> /var/log/clear.log ;  
         fi;  
		 if [[ -f $file ]] && [[ ${exist2} = yes ]];  
         then  
           echo ‘‘ > $file;  
           echo $(date) $file "clear log ok!" >> /var/log/clear.log ;  
         fi;  
     done;
	 
     for file1 in $tomcatDir;  
     do  
         exist2=`echo $file1 | awk ‘{if(match($0,/\.out/)) print "yes"}‘`;  
         if [[ -f $file1 ]] && [[ ${exist2} = yes ]];  
         then  
           echo ‘‘ > $file1;  
           echo $(date) $file1 "clear log ok!" >> /var/log/clear.log ;  
         fi;  
     done;
	 
	 
	 for file in $tomcatDir3;  
     do  
         exist=`echo $file | awk ‘{if(match($0,/\.log/)) print "yes"}‘`;
		 exist2=`echo $file | awk ‘{if(match($0,/\.out/)) print "yes"}‘`;		 
         if [[ -f $file ]] && [[ ${exist} = yes ]];  
         then  
           echo ‘‘ > $file;  
           echo $(date) $file "clear log ok!" >> /var/log/clear.log ;  
         fi;  
		 if [[ -f $file ]] && [[ ${exist2} = yes ]];  
         then  
           echo ‘‘ > $file;  
           echo $(date) $file "clear log ok!" >> /var/log/clear.log ;  
         fi;  
     done;
	 
     for file1 in $tomcatDir4;  
     do  
         exist2=`echo $file1 | awk ‘{if(match($0,/\.out/)) print "yes"}‘`;  
         if [[ -f $file1 ]] && [[ ${exist2} = yes ]];  
         then  
           echo ‘‘ > $file1;  
           echo $(date) $file1 "clear log ok!" >> /var/log/clear.log ;  
         fi;  
     done;
	 

	 
   fi;   
     
   
done 

  

linux的定时删除备份及删除文件后无法释放资源的脚本内容

标签:auto   echo   linu   rm -rf   time   grep   脚本   logs   deploy   

原文地址:https://www.cnblogs.com/lxj666/p/11358366.html

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