使用scp时for循环中的@

时间:2010-07-19 12:06:09

标签: ant scp

请看一下这一行:

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

双@@引起问题。而不是user:pass @ server它显示为user:passserver,因此无法连接到远程ssh服务器。

你怎么告诉蚂蚁离开@ be?

这是我的代码:

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

在echo命令中,它显示如下:

  

将LibraryName复制到   myserver.domain.com   用户名:密码@ {服务器}:/ TMP /库名称/ LibraryBar

2 个答案:

答案 0 :(得分:3)

您可以通过加倍@来逃避@@

所以在你的情况下它将是:

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

BTW,同样的规则适用于$转义,$$只打印$

回复OP的评论

示例:

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

这会产生:

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

所以,你的问题出在其他地方,可能是在循环设置代码中

答案 1 :(得分:1)

它似乎是该行中的拼写错误 - 第二句@应更改为$${server_username}:${server_password}@${server}:/tmp