【问题标题】:ANT sshexec commandANT sshexec 命令
【发布时间】:2020-12-18 16:34:03
【问题描述】:

我在 bw 脚本中使用 sshexec 来检查远程服务器上是否存在文件,但输出属性似乎有一个额外的新行。

尝试添加 'sed -r '/^\s*$/d',但这似乎也无济于事。

<sshexec trust="true"  
    host="${Deploy.remote_hostname}" 
    username="${Deploy.username}"   
    verbose="true"
    password="${Deploy.password}"
    command="test -f ${Deploy.remote_propfile_loc}${Deploy.application_name}_${Deploy.application_version}_@{currentappspace}_@{currentappnode}.substvar &amp;&amp; echo 'true'||echo 'false' | sed -r '/^\s*$/d';"
    failonerror="true"
    outputproperty="file.exists"/>
<echo>this is file "${file.exists}" "Deploy.true"</echo> 

cmd : test -f /home/tibco/jenkins/BW_DEV_Login/concatName.application_1.0_AS1_AS1_AN1.substvar && echo 'true'||echo 'false' | sed -r '/^\s*$/d';
true
Disconnecting from dewaserv7377.smartgrid.local port 22
Caught an exception, leaving main loop due to Socket closed
this is file "true
" "Deploy.true"

【问题讨论】:

  • echo 默认情况下(通常我认为)附加一个换行符。您也许可以使用“-n”将其关闭,或使用 printf 代替 echo。

标签: ssh ant sh


【解决方案1】:

对于这类事情,我建议使用 Ant 的 sshsession 任务在远程机器上运行原生 Ant 任务,而不是使用 sshexec 嵌入复杂的 shell 命令。

    <property
        name="file.name"
        value="${Deploy.remote_propfile_loc}${Deploy.application_name}_${Deploy.application_version}_@{currentappspace}_@{currentappnode}.substvar"
    />

    <sshsession
        trust="true"  
        host="${Deploy.remote_hostname}" 
        username="${Deploy.username}"   
        password="${Deploy.password}"
        failonerror="true"
    >
        <condition property="file.exists" value="true" else="false">
            <available file="${file.name}" />
        </condition>
    </sshsession>

    <echo>this is file "${file.exists}" "Deploy.true"</echo>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    相关资源
    最近更新 更多