0
votes

I am using sshexec in bw script to check if a file exists on a remote server, but the output property seems to be having a extra new line.

Tried adding 'sed -r '/^\s*$/d', but that doesn't seems to help either.

<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"
1
echo by default (usually I think) appends a newline. You might be able to use "-n" to switch that off, or use printf instead of echo. - martin clayton

1 Answers

0
votes

For this sort of thing, I would recommend using Ant's sshsession task to run native Ant tasks on the remote machine, instead of using sshexec to embed a complex shell command.

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