shell如下:#!/bin/bash
echo $1
echo $1
MY_TOMCAT='/home/was/test/tomcat'
PROJECT_NAME='dqmhsm'
WAR=$1
echo $MY_TOMCAT
echo $PROJECT_NAME
#dep webapps
dep_project(){
echo "dep project start!"
if [ -n "$MY_TOMCAT" ];then
PID=`ps -ef|grep $MY_TOMCAT |grep -v 'grep' | awk '{print $2}'`
if [ -n "$PID" ];then
echo kill process $PID
for i in $PID
do
kill -9 $i
done
else echo process had stopped!
fi
sleep 5
#echo rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*
rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*&&echo delete file success!
echo cp $WAR $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
cp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
cd $MY_TOMCAT/webapps/$PROJECT_NAME/
jar -vxf $WAR
#rm -rf $WAR
sh $MY_TOMCAT/bin/startup.sh
sleep 5
tail -f $MY_TOMCAT/logs/catalina.out
else echo tomcat path is null
fi
}
if [ -n "$WAR" ];then
dep_project;
else
echo "dep war is null"
fi
运行结果:
[was@wtjs38 test]$ ./dep.sh test.war
test.war
test.war
/home/was/test/tomcat
dqmhsm
dep project start!
process had stopped!
delete file success!
cp test.war /home/was/test/tomcat/webapps/dqmhsm/test.war
cp: missing destination file operand after “/home/was/test/tomcat/webapps/dqmhsm/test.war”
慕哥6287543
慕村225694