Search code examples
antbuildssh

sshexec ant task: environment variables


I'm using SSHExec ant task to connect to a remote host and I depend on the environment variables that are set on the remote host in order to be able to successfully execute some commands.

<sshexec host="somehost"
    username="${username}"
    password="${password}"
    command="set"/>

Using the task the env. variables that are outputed are not the same as the ones I get when I log in using an SSH Client.

How can I make the env. variables of the remote host avaiable for the session?


Solution

  • Actually there is something you can do about the fact it doesn't start a shell. Use the following:

    <sshexec command="/bin/bash -l yourScript.sh" .../>
    

    Using /bin/bash -l will start an login shell then execute your script within that shell. It would be exactly as if you had a version of sshexec that properly starts up a login shell. It has to be a script. If you want to run a single executable command you can do this:

    <sshexec command="/bin/bash -l -c 'echo $CATALINA_HOME'" .../>