ANT-sshexec命令

ANT-sshexec命令,ssh,ant,sh,Ssh,Ant,Sh,我在bw脚本中使用sshexec检查远程服务器上是否存在文件,但是输出属性似乎有一个额外的新行 尝试添加'sed-r'/^\s*$/d',但这似乎也没有帮助 <sshexec trust="true" host="${Deploy.remote_hostname}" username="${Deploy.username}" verbose="true" passwo

我在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"

这是文件“${file.exists}”“Deploy.true”
cmd:test-f/home/tibco/jenkins/BW_DEV_Login/concatName.application_1.0_AS1_AS1_AN1.subsvar&&echo'true'| echo'false'| sed-r'/^\s*$/d';
真的
断开与dewaserv7377.smartgrid.local端口22的连接
捕获到异常,由于套接字关闭而离开主循环
这是“真实”文件
“Deploy.true”

对于这类事情,我建议使用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>

这是文件“${file.exists}”“Deploy.true”
echo默认情况下(通常我认为)会添加一个换行符。您可以使用“-n”来关闭它,或者使用printf而不是echo。