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>
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)
Hope this helps!