How to execute sudo command with ant sshexec
I am trying to execute a command on a remote server using 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 is as follows:
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 can I use ant to execute a remote command using sudo?
Thank:)
+3
source to share
1 answer
Yes, maybe it can be duplicated like this:
How can I pass password to su / sudo / ssh without overriding TTY?
But anyway, one solution to these problems is similar to the answer in the most voted answer
<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 option is for reading from standard input.
+4
source to share