bash脚本和蚂蚁

时间:2017-04-04 20:29:43

标签: java bash shell ant

我有一个构建文件,可以调用这样的脚本:

<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
}

使用“ant -buildfile deploy.xml”运行构建文件时,我获得了构建成功的消息,但是带有append()函数的第二个脚本无法正常运行。它不会将jar文件附加到wrapper.conf文件

我在2天前工作,因为sudo以root用户身份登录。但是当我弄乱计数变量并且它停止工作时发生了一些事情。如果我把日志条目放在附加脚本中,它会说“追加需要1个参数”,即使我发送了参数。 我开始认为它不是脚本,而是它可以做的事情。

有什么想法?

1 个答案:

答案 0 :(得分:0)

原来这个if语句有问题。

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

这总是返回true,因此脚本每次都会退出,而不是前进。 所以改为正确的检查:

if [ -z $1 ];
 exit
fi

现在一切都很好!! :)