清理tomcat

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
#Program:
 
#1.输入目录
read -p "请输入要清理包含tomcat的目录:" dir
if [ ${dir} == "" -o ! -d ${dir} ]; then
    echo "$dir 不存在"
    exit 1
fi


dirList=$(find ${dir} -name catalina.sh)
for binDir in $dirList
do
    fileName=$(echo ${binDir}| sed 's/\/bin\/catalina.sh$//g')
    echo ================clear ${fileName}==================
   
    logFileName=${fileName}/logs
    if [ ! -d $logFileName ]; then
      mkdir ${logFileName}
    fi 
   
    catalinaFileName=${logFileName}/catalina.out
    if [ ! -f $catalinaFileName ]; then
      touch ${catalinaFileName}
    fi

    cd ${logFileName}
    find .  -type f  ! -name catalina.out ! -name .  -exec rm -f {} \;
    echo ''>${catalinaFileName}
    echo ls ${logFileName}
    ls -l  ${logFileName}
    echo -e '\n\n'

    appbakFileName=${fileName}/appbak
    if [ -d $appbakFileName ]; then
         cd ${appbakFileName}
         ls -lt|sed -n '3,$p'|awk '{print $9}'|awk '{print "rm -rf",$1}'|sh
         echo ls ${appbakFileName}
         ls -l
         echo -e '\n\n'
    fi 

    tempFileName=${fileName}/temp
    if [ -d $tempFileName ]; then
         cd ${tempFileName}
         ls -lt|sed -n '3,$p'|awk '{print $9}'|awk '{print "rm -rf",$1}'|sh
         echo ls ${tempFileName}
         ls -l
         echo -e '\n\n'
    fi

done