Tutorial :The @ in a for loop while using scp


Please take a look at this line:


The double @@ causes problems. Instead of user:pass@server it displays as user:passserver and therefore is unable to connect to the remote ssh server.

How do you tell ant to leave the @ be?

This is my code:

<for list="${externalLibs}" param="library">     <sequential>      <for list="${servers}" param="server">         <sequential>          <echo> Copying @{library} to @{server} ${server_username}:${server_password}@@@{server}:/tmp/@{library}/${@{library}}/           </echo>          <scp todir="${server_username}:${server_password}@@@{server}:/tmp/@{library}/${@{library}}/">                 <fileset dir="/tmp/@{library}/${@{library}}/" />           </scp>        </sequential>       </for>    </sequential>   </for>  

In the echo command, it shows like this:

Copying LibraryName to myserver.domain.com username:password@{server}:/tmp/LibraryName/LibraryBar


You escape @ by doubling it, as in @@.

So in your case it will be:


BTW, same rule goes for $ escape, $$ just prints a $.

In reply to OP's comment


<property name="server_username" value="user-name"/>  <property name="server_password" value="passwd"/>    <for list="s1.foo.bar,s2.foo.bar,s3.foo.bar" param="server">    <sequential>      <echo message="${server_username}:${server_password}@@@{server}:/tmp"/>    </sequential>  </ac>  

This produces:

 [echo] user-name:passwd@s1.foo.bar:/tmp   [echo] user-name:passwd@s2.foo.bar:/tmp   [echo] user-name:passwd@s3.foo.bar:/tmp  

So, your problem is somewhere else, probably in the loop setup code


It seems that it is a typo in that line - second last @ should be changed to $: ${server_username}:${server_password}@${server}:/tmp

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »