因为每次工程部署到linux中后,都要重启tomcat+清除work缓存,每次操作命令都要重复的打好多,kill、start等等

而且在技术经理的建议下买了一本shell编程的书,自学了下整理了一份重启tomcat和自动清除此tomcat下缓存的sh脚本,供大家使用,还是比较方便的,现在测试部门的小伙伴们都在用我的脚本哈哈,很方便的说~~

现在贴上sh代码

#!/bin/sh
#==================================
#minxing
#2013-12-6
#==================================

current_course=$1
if [ -z "$current_course" ];then
        echo "your input is null or course is not correct"
        exit
else
        echo "your input tomcat ===============> $current_course"
fi
unset course_result
course_result=`ps -ef|grep $current_course|grep java|grep -v grep|awk '{print $2}'`

length=`echo $course_result | awk '{ print $2; }'`
if [ "$length" != "" ];then
        echo "your input tomcat is too more"
        exit
else
        echo "the $current_course pid is >>>>>>>>>>>>> $course_result" 
fi
while [ true ]
do
        course_result=`ps -ef|grep $current_course|grep java|grep -v grep|awk '{print $2}'`
        if [ "$course_result" == "" ];then
                echo "-----------------$current_course is clear----------------"
                break
        else 
                sleep 1
                echo "-----------------$current_course is clearing,please wait a moment---------------"
                kill -9 $course_result
        fi
done

#================================
#clear Catalina
#================================

work_url=`echo $(pwd)/$current_course/work`
pwd_url = `echo $(pwd)`
echo "work url is:$work_url== begin clear work"

cd $work_url
if [ -e Catalina ];then
        rm -rf *
else
        echo "----------------Catalina is clear-----------------"
fi
echo "------------------Catalina have cleared----------------------"

#================================
#reload the 8084
#================================

/$pwd_url/$current_course/bin/startup.sh
course_result=`ps -ef|grep $current_course|grep java|grep -v grep|awk '{print $2}'`
echo "the current $current_course pid is >>>>>>>>>>>>> $course_result after kill"

使用方法:将这个sh文件放在和tomcat同级目录就行了,也就是和tomcat并行

操作过linux的童鞋肯定都知道:例如这个文件名叫 test.sh

那么指令就是 ./test.sh tomcat名称

下面就是自动的清除缓存+重启啦哈哈