3

i'm trying to execute a command in a remote server with sudo like this

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

But the server response the following:

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

So, how i can use ant to execute a remote command with sudo?

Thanks :)

Enrique San Martín
  • 2,202
  • 7
  • 30
  • 51
  • possible duplicate of [Passing a password to "su" command over sshexec from ant](http://stackoverflow.com/questions/10919381/passing-a-password-to-su-command-over-sshexec-from-ant) – Mark O'Connor Nov 21 '14 at 21:41

1 Answers1

4

Yes, maybe it can be duplicated like this:

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

But anyway, one solution to this problems is like says in the most voted answer of the

<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>

The -S parameter is for read from standart input.

Community
  • 1
  • 1
Enrique San Martín
  • 2,202
  • 7
  • 30
  • 51