2017-04-04 124 views
0

我有一个调用这样一个脚本构建文件:的bash脚本和蚂蚁

<exec executable="/bin/bash" failonerror="true"> 
     <arg value="wrapper_generatedConfig.sh"/> 
</exec> 

的wrapper_generatedConfig.sh:

#!/bin/bash 

MAIN_PATH=/opt/app/Gateway/gateway-1.6 
LIB_PATH=$MAIN_PATH/lib 
XML_LIB_PATH=$MAIN_PATH/lib/xml 
PROD_LIB_PATH=$MAIN_PATH/prod_lib 
ABN_LIB_PATH=$MAIN_PATH/abn_lib 
ABN_LIB_EXT_PATH=$MAIN_PATH/abn_lib/ext 

WS_LIB_PATH=$MAIN_PATH/web/CPMessageCenterWebSrvc/WEB-INF/lib 

WRAPPER_CONFIG_FILENAME=$MAIN_PATH/config/wrapper.conf 
WRAPPER_CONFIG_INITIAL=$MAIN_PATH/config/initialWrapper.conf 

CP="" 

declare -i count=1 

WRAPPER=wrapper.java.classpath. 
rm $WRAPPER_CONFIG_FILENAME 

cp $WRAPPER_CONFIG_INITIAL $WRAPPER_CONFIG_FILENAME 

#call the other script first before calling its function inside for loops. 
. wrapper_cpappend.sh 

for a in $LIB_PATH/*.jar 
     do append $LIB_PATH/$a 
done 

for a in $XML_LIB_PATH/*.jar 
     do append $XML_LIB_PATH/$a 
done 

for a in $PROD_LIB_PATH/*.jar 
     do append $PROD_LIB_PATH/$a 
done 

for a in $ABN_LIB_EXT_PATH/*.jar 
     do append $ABN_LIB_EXT_PATH/$a 
done 

for a in $ABN_LIB_PATH/*.jar 
     do append $ABN_LIB_PATH/$a 
done 

append $WS_LIB_PATH/axis.jar 
append $WS_LIB_PATH/saaj.jar 
append $WS_LIB_PATH/wsdl4j.jar 
append $WS_LIB_PATH/commons-discovery.jar 
append $WS_LIB_PATH/commons-logging.jar 
append $WS_LIB_PATH/axis-ant.jar 


# Clean up the variables defined. 
CP="" 

echo ------------------------------------------------ 
if [ -f "$WRAPPER_CONFIG_FILENAME" ]; 
then 
     echo $WRAPPER_CONFIG_FILENAME has been created. 
else 
     echo Error in creating $WRAPPER_CONFIG_FILENAME! 
fi 
echo ------------------------------------------------ 

sleep 2 

其中要求wrapper_cpappend.sh。 的wrapper_cpappend.sh:

#!/bin/bash 

echo $count 
if [ $1="" ]; then 
    exit 
fi 

append() 
{ 
    count=$count+1 
    echo wateves 
    CP=$WRAPPER$count=$1 
    echo $CP >> $WRAPPER_CONFIG_FILENAME 
} 

当使用“蚂蚁-buildfile deploy.xml”我得到建立成功的消息,但用的append()函数的第二个剧本没有得到正常运行,运行构建文件。它不会将jar文件附加到wrapper.conf文件

我在2天前得到了这个工作,因为sudo以root用户身份登录。但是当我搞乱count变量并且它停止工作时发生了一些事情。如果我把日志条目放在append脚本中,它会说“append needs 1 arg”,即使我正在发送参数。 我开始认为它不是脚本和它做的东西蚂蚁..

任何想法??

回答

0

如果声明有问题,结果如此。

if [ $1="" ]; then 
    exit 
fi 

这总是返回true,因此脚本每次都不会前进。 因此,将其更改为适当的检查:

if [ -z $1 ]; 
exit 
fi 

现在一切都很好! :)