2014-11-21 85 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參數用於從標準輸入讀取。