The @ in a for loop while using scp

浪尽此生 提交于 2020-01-03 17:13:10

问题


Please take a look at this line:

${server_username}:${server_password}@@{server}:/tmp

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


回答1:


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

So in your case it will be:

${server_username}:${server_password}@@@{server}:/tmp

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

In reply to OP's comment

Example:

<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




回答2:


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



来源:https://stackoverflow.com/questions/3280858/the-in-a-for-loop-while-using-scp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!