linux服务器重启tomcat并且清除work缓存的脚本

因为每次工程部署到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名称

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

转载于:https://www.cnblogs.com/hulalalastar/p/5363817.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值