ant - contraseña de entrada para sshexec

I have an ant script on a public server available to multiple users. I want to input a password into a script securely and use it for multiple targets. The following code gets a password with input, but the variable is not being passed to the sshexec task.

Will this work or is there a better way to do it?

<target name="get_password">
        <input message="Enter Your Password:>" addproperty="password">
                <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
        </input>
</target>

<target name="create_tmp_dir">
        <sshexec host="${host}"
        username="${username}"
        password="${password}"
        command="mkdir ${tmp_dir}" />
</target>

preguntado el 30 de enero de 12 a las 19:01

This should work. is the dependency between two tasks correct? Did you try running them as single command? Possibly add some <echo > and show us the output? -

@Jajan I tested <echo message="${password}"/> on each target. On the "get_password" target, the echo returns the proper value. But the "create_tmp_dir" target returns ${password}. It appears the addproperty is not creating a variable for the build file. I also tried this <target name="create_tmp_dir" depends="get_password"> and the authentication failed for my ssh session. -

The change '<target name="create_tmp_dir" depends="get_password"> ' is the correct one. After this what is the password value in the create_tmp_dir target? -

An echo shows the proper value, but authentication still fails -

There may be a bug in ant ? What is your version? I have added ssh tag. Let us see if that comes with better answers. -

1 Respuestas

Ok...I see that I am a year late but for new comers this is how I solved the problem. My goal was to execute a command as root without revealing my password (obviously)

<target name="getServerCredentials" unless="${server.user}">
    <input message="${server-name} user:" addproperty="server.user" />
    <input message="${server.user} password:" addproperty="server.pass">
        <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
    </input>
</target>


<target name="execute-command" depends="getServerCredentials">
    <sshexec host="${server-name}" username="${server.user}" password="${server.pass}" command="~./become-root.sh" inputproperty="server.pass"/>
</target>

Finally I've created a bash script in ~/become-root.sh in my server that looked like this

#!/bin/sh
read var
echo $var | sudo -S whoami --

If you call execute-command task you can now run commands as sudo (assuming that your user is sudoer)

¡Espero que esto ayude!

Respondido 08 Feb 13, 08:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.