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

#!/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 

  

posted @ 2019-08-15 15:42  lxj666  阅读(274)  评论(0编辑  收藏  举报