You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Stein Inge Morisbak <St...@BEKK.no> on 2011/02/01 21:24:16 UTC

ant exec task: ssh username contains spaces, how to escape?

I am trying to call ssh using the ant exec task from maven. My problem is that I can't figure out how to escape spaces in usernames. I have tried:

<exec executable="sed" failonerror="true" inputstring="stein inge morisbak" outputproperty="username">
   <arg value="s/ /\\ /g" />
</exec>

<exec executable="ssh" failonerror="true">
   <arg value="${username}@localhost" />
   <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>


... and also:

<exec executable="ssh" failonerror="true">
   <arg value="&quot;stein inge morisbak&quot;@localhost" />
   <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>

... and finally:

<exec executable="ssh" failonerror="true">
   <arg value="'stein inge morisbak'@localhost" />
   <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>

... but no luck :-(

Any ideas?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: ant exec task: ssh username contains spaces, how to escape?

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Stein Inge,

I am sure that ant does a good at keeping together a command line 
argument defined with <arg value=" "/>

In fact I have even checked this assertion on Windows/Cygwin

- build.xml

<project name="testspaceinarg">
<exec executable="bash" failonerror="true">
<arg value="./parrot.sh" />
<arg value="-tt" />
<arg value="stein inge morisbak@localhost" />
<arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>
</project>

- contents of parrot.sh

#!/bin/bash
i=0
for arg in "$@" ; do
         i=$(( $i + 1 ))
     echo $i " argument : " $arg " END"
done

- output

Buildfile: C:\dev\build.xml

      [exec] 1  argument :  -tt  END
      [exec] 2  argument :  stein inge morisbak@localhost  END
      [exec] 3  argument :  if [ -f /tmp/test.txt ]; then rm -f 
/tmp/test.txt ; fi  END

BUILD SUCCESSFUL
Total time: 0 seconds


Can you test the same on your Mac ?

If it behaves the same as what I am showing, it would mean that the ssh 
command line client does not support user name argument when it is 
splitted by spaces.


Regards,

Antoine

On 2/2/2011 3:44 AM, Stein Inge Morisbak wrote:
> That's what I thought also, but in practice it doesn't work, at least not on my machine (mac os x)
>
> I know about the sshexec task, but the problem with this task is that it is not possible to give options to the ssh command. I left that out in my example, but I need to give the '-tt' option to ssh. Like this:
>
> <exec executable="ssh" failonerror="true">
>       <arg value="-tt" />
>     <arg value="stein inge morisbak@localhost" />
>     <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
> </exec>
>
> Regards,
> Stein Inge
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: ant exec task: ssh username contains spaces, how to escape?

Posted by Stein Inge Morisbak <St...@BEKK.no>.
That's what I thought also, but in practice it doesn't work, at least not on my machine (mac os x)

I know about the sshexec task, but the problem with this task is that it is not possible to give options to the ssh command. I left that out in my example, but I need to give the '-tt' option to ssh. Like this:

<exec executable="ssh" failonerror="true">
     <arg value="-tt" /> 
   <arg value="stein inge morisbak@localhost" />
   <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>

Regards,
Stein Inge

On 1. feb. 2011, at 23.04, Antoine Levy-Lambert wrote:

> Hi,
> 
> in theory, this should work :
> 
> <exec executable="ssh" failonerror="true">
>    <arg value="stein inge morisbak@localhost" />
>    <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
> </exec>
> 
> when you use <arg value="'/> it generates a single argument.
> 
> BTW there is also a sshexec task in ant. Maybe it would work better ?
> 
> Regards,
> 
> Antoine
> 
> On 2/1/2011 3:24 PM, Stein Inge Morisbak wrote:
>> I am trying to call ssh using the ant exec task from maven. My problem is that I can't figure out how to escape spaces in usernames. I have tried:
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: ant exec task: ssh username contains spaces, how to escape?

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hi,

in theory, this should work :

<exec executable="ssh" failonerror="true">
    <arg value="stein inge morisbak@localhost" />
    <arg value="if [ -f /tmp/test.txt ]; then rm -f /tmp/test.txt ; fi" />
</exec>

when you use <arg value="'/> it generates a single argument.

BTW there is also a sshexec task in ant. Maybe it would work better ?

Regards,

Antoine

On 2/1/2011 3:24 PM, Stein Inge Morisbak wrote:
> I am trying to call ssh using the ant exec task from maven. My problem is that I can't figure out how to escape spaces in usernames. I have tried:
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org