shell如下:#!/bin/bashecho $1echo $1MY_TOMCAT='/home/was/test/tomcat'PROJECT_NAME='dqmhsm'WAR=$1echo $MY_TOMCATecho $PROJECT_NAME#dep webappsdep_project(){echo "dep project start!"if [ -n "$MY_TOMCAT" ];thenPID=`ps -ef|grep $MY_TOMCAT |grep -v 'grep' | awk '{print $2}'`if [ -n "$PID" ];then echo kill process $PIDfor i in $PIDdo kill -9 $idoneelse echo process had stopped!fisleep 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/$WARcp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WARcd $MY_TOMCAT/webapps/$PROJECT_NAME/jar -vxf $WAR#rm -rf $WARsh $MY_TOMCAT/bin/startup.shsleep 5tail -f $MY_TOMCAT/logs/catalina.outelse echo tomcat path is nullfi}if [ -n "$WAR" ];thendep_project;else echo "dep war is null"fi运行结果:[was@wtjs38 test]$ ./dep.sh test.war test.wartest.war/home/was/test/tomcatdqmhsmdep project start!process had stopped!delete file success!cp test.war /home/was/test/tomcat/webapps/dqmhsm/test.warcp: missing destination file operand after “/home/was/test/tomcat/webapps/dqmhsm/test.war”
2 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
把shell里面的cp test.war /home/was/test/tomcat/webapps/dqmhsm/test.war改成
cp test.war /home/was/test/tomcat/webapps/dqmhsm/
慕村225694
TA贡献1880条经验 获得超4个赞
#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
请注意,这几句是在函数 “dep_project()”里面的,而函数里面的位置变量是在调用函数时传入的。并不和脚本运行时的一致。上例中调用“dep_project”并没有传入参数。所以在函数中"$1"是空值。
可以将
cp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
改为
cp $WAR $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
或将:
dep_project;
改为
dep_project $WAR;
。
- 2 回答
- 0 关注
- 154 浏览
添加回答
举报
0/150
提交
取消