linux的定时删除备份及删除文件后无法释放资源的脚本内容
Posted lxj666
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于linux的定时删除备份及删除文件后无法释放资源的脚本内容的主要内容,如果未能解决你的问题,请参考以下文章
linux删除文件后空间无法释放?lsof没有结果。重启无效。请问各位高手还有别的办法吗?