for循环中的@同时使用scp [英] The @ in a for loop while using scp
问题描述
请在该行一起来看看:
$ {} server_username:$ {} server_password @@ {}服务器:/ tmp目录
双@@导致问题。取而代之的用户:通@服务器时,它显示为用户:passserver,因此无法连接到远程SSH服务器
。你怎么知道蚂蚁离开@是什么?
这是我的code:
<用于列表=$ {} externalLibs参数=库>
<&连续GT;
<用于列表=$ {}的服务器参数=服务器>
<&连续GT;
<回声>复制@ {}库向@ {服务器} $ {} server_username:$ {} server_password {@@@服务器}:/ tmp目录/ @ {库} / $ {@ {库}} /
< /回声>
< SCP todir =$ {} server_username:$ {} server_password {@@@服务器}:/ tmp目录/ @ {库} / $ {@ {库}} />
<文件集DIR =/ tmp目录/ @ {库} / $ {@ {库}} //>
< / SCP>
< /顺序>
< /为>
< /顺序>
< /为>
在echo命令,它显示是这样的:
复制到库名称
myserver.domain.com
用户名:密码@ {}服务器:/ tmp目录/库名称/ LibraryBar
块引用>解决方案您逃离
@
通过加倍它,如@@
。所以你的情况将是:
$ {} server_username:$ {} server_password {@@@服务器}:/ tmp目录
顺便说一句,同样的规则也适用于
$
逃生,$
只是打印出$
。在回答OP的评论
例如:
<属性名=server_usernameVALUE =用户名/>
<属性名=server_passwordVALUE =passwd文件/><用于列表=s1.foo.bar,s2.foo.bar,s3.foo.bar参数=服务器>
<&连续GT;
<回声消息=$ {} server_username:$ {} server_password {@@@服务器}:/ tmp目录/>
< /顺序>
< / AC>这会产生:
[回应]用户名:passwd@s1.foo.bar:/ tmp目录
[回应]用户名:passwd@s2.foo.bar:/ tmp目录
[回应]用户名:passwd@s3.foo.bar:/ tmp目录所以,你的问题是在其他地方,可能是在环路设置code
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
解决方案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
这篇关于for循环中的@同时使用scp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!