Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute sudo command with ant sshexec

Tags:

command

sudo

ant

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

like image 428
Enrique San Martín Avatar asked Aug 28 '26 13:08

Enrique San Martín


1 Answers

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.

like image 55
Enrique San Martín Avatar answered Aug 30 '26 11:08

Enrique San Martín



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!