我正在尝试像这样使用 sudo 在远程服务器中执行命令
<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:
那么,我如何使用 ant 通过 sudo 执行远程命令?
谢谢:)
最佳答案
是的,也许可以这样复制:
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 参数用于从标准输入读取。
关于ant - 如何用ant sshexec执行sudo命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27061348/