ant - 如何用ant sshexec执行sudo命令

标签 ant command sudo

我正在尝试像这样使用 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/

相关文章:

java - 从 Ant 启动/停止 Tomcat - NoClassDefFoundError

database - 如何通过 Ant (版本控制)更新数据库?

delphi - 通过Delphi与命令提示符进行通信

python - 以 root 身份运行结构脚本

python - 以 root 身份在 Eclipse 中运行 Python 项目

ant - 更新属性文件后重新加载属性

java - 用于编码的不可映射字符

gdb - 在GDB中,如何在程序停止时自动执行命令? (如显示)

windows - 如何在 Windows 上的 Node.js 中创建全局命令

macos - 如何阻止 OSX 在终端中对 sudo 命令发出警告?