标签: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
标签:auto echo linu rm -rf time grep 脚本 logs deploy
原文地址:https://www.cnblogs.com/lxj666/p/11358366.html