Ant的SCP問題

下面是一段ANT,目的是針對一堆server做程式的佈署工作
一般我們習慣用build.properties作為參數設定檔
而也可以動態的用-DKEY=VALUE作為臨時的參數輸入...
而實際上的執行檔案是build.xml...

#build.properties
SERVER_LIST=11.11.11.11,11.11.11.12,11.11.11.13
USER=xxxx
PASSWD=oooo
TMP_FOLDER=/tmp

#build.xml
<target name="Deploy">
    <antcall target="Wrapper code" />

    <!-- 檢查是否有手動輸入-DSERVER=xx.xxx.xxx.xxx -->
    <condition property="SERVER.set" else="false">
      <isset property="SERVER"/>
    </condition>
    <echo>Is specify server? ${SERVER.set}</echo>

    <!-- 如指定-DSERVER=xx.xxx.xxx.xxx時候,忽略設定檔案,直接進行deploy -->
    <ac:if>
      <equals arg1="${SERVER.set}" arg2="true"/>
      <then>
        <ac:var name="SERVER_LIST" value="${SERVER}"/>
      </then>
    </ac:if>

    <echo>Working Server: ${SERVER_LIST}</echo>

    <!-- 針對SERVER或參數檔設定的SERVER_LIST進行程式的部屬動作 -->
    <ac:for list="${SERVER_LIST}" param="cn">
      <sequential>
        <echo>==================================================================</echo>
        <scp file="${TMP_FOLDER}/code.tar.gz"
          trust="true"
          todir="${USER}@@@{cn}:/home/user/"
          password="${PASSWD}"/>
      </sequential>
    </ac:for>
  </target>

而特別要注意的是紅色的三個"@"
因為scp tag所提供的欄位todir裡面需要放置user@server_ip:file_path
但如果這邊直接吃cn參數,就會變成"user@@{cn}:file_path"
此時兩個"@"在一起時候,<echo>出來得訊息會變成"user@{cn}:file_path"
似乎有個@變成跳脫字元而消失...
經過多次測試...既然他跳脫,那就多給他一個...而且居然可以!



這個網誌中的熱門文章

Bash判斷參數是否存在

Node.js package : forever