【问题标题】:bash scripts and antbash 脚本和蚂蚁
【发布时间】:2017-04-04 20:29:42
【问题描述】:

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

<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 个参数”。 我开始认为它不是脚本,而是它可以做的事情。..

有什么想法吗??

【问题讨论】:

    标签: java bash shell ant


    【解决方案1】:

    原来这个 if 语句有问题。

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

    这总是返回 true,因此脚本每次退出时都不会继续前进。 因此将其更改为正确的检查:

    if [ -z $1 ];
     exit
    fi
    

    现在一切都很好! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多