2014-11-21 87 views
3

我试图在远程服务器上执行命令使用sudo这样如何执行sudo命令与蚂蚁sshexec

<target name="remote-test"> 
    <sshexec host="${remote.host}" 
     username="${remote.user}" 
     password="${remote.pass}" 
     trust="true" 
     usepty="true" 
     command="sudo ls /home/myuser" /> 
</target> 

但是服务器响应如下:

Buildfile: build.xml 
remote-test: 
    [sshexec] Connecting to 0.0.0.0:22 
    [sshexec] cmd : sudo ls /home/myuser 
    [sshexec] [sudo] password for myuser: 

所以,我如何使用蚂蚁来执行远程命令与sudo?

谢谢:)

+0

可能的重复[将密码传递给“su”命令通过ant从sshexec](http://stackoverflow.com/questions/10919381/passing-a-password-to-su-command-over-sshexec-from -蚂蚁) – 2014-11-21 21:41:10

回答

4

是的,也许它可以重复这样的:

How to pass the password to su/sudo/ssh without overriding the TTY?

但无论如何,一个解决这个问题,就像是说,在

最投票回答
<target name="remote-test-jboss"> 
    <sshexec host="${remote.host}" 
     username="${remote.user}" 
     password="${remote.pass}" 
     command="echo ${remote.pass}| sudo -S ls /home/myserver" 
     trust="true" 
    /> 
</target> 

-S参数用于从标准输入读取。