title: Ant SSHExec task does not return when calling Tomcat startup.sh
body: <p>From my (Windows) desktop or the (Windows or Unix) Jenkins server (which I believe uses the same underlying JSch technology), I can't seem to call the startup.sh script in the Tomcat bin dir as I want to. Tomcat (7) lives on a Solaris 9 server. I have rather basic Unix knowledge.</p>
  
  <p>It executes successfully (Tomcat starts fine) but never returns until the Tomcat process is killed. I imagine other similar scripts would have the same behavior.</p>
  
  <p>Example ant task (the commands are the same as I would put in Jenkins "Execute shell script on remote host" build task)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project name="remote-tomcat-controls" basedir="."&gt;
      &lt;property name="hostname"&gt;someserver&lt;/property&gt;
      &lt;property name="username"&gt;someuser&lt;/property&gt;
      &lt;property name="password"&gt;somepassword&lt;/property&gt;
      &lt;property name="port"&gt;22&lt;/property&gt;
      &lt;property name="tomcathome"&gt;~/tomcat&lt;/property&gt;
      &lt;target name="start-tomcat"&gt;
          &lt;sshexec   host="${hostname}" port="${port}" username="${username}" 
              password="${password}" trust="true"  
              command=". ~/.profile; cd ${tomcathome}/bin; ./startup.sh" /&gt;
      &lt;/target&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>This starts Tomcat successfully but the task never returns unless/until the Tomcat process is killed on the server:</p>
  
  <pre><code>start-tomcat:
    [sshexec] Connecting to someserver:22
    [sshexec] cmd : . ~/.profile; cd ~/tomcat/bin; ./startup.sh
  </code></pre>
  
  <p>There are 3 commands involved:</p>
  
  <ul>
  <li>Import users profile so Java is in the path</li>
  <li>Change to the tomcat bin dir so relative paths to log files work</li>
  <li>Start Tomcat</li>
  </ul>
  
  <p>I have tried moving these commands into a new script on the server, and have the Ant task simply call that, same results.</p>
  
  <p>I have tried prepending the command with nohup and ending with &amp;, no luck either.</p>
  
  <p>Results you get when running the startup.sh script during an interactive ssh session:</p>
  
  <pre><code>$ ./startup.sh
  Using CATALINA_BASE:   /home/ebiztest/tomcat-datasheets
  Using CATALINA_HOME:   /home/ebiztest/tomcat-datasheets
  Using CATALINA_TMPDIR: /home/ebiztest/tomcat-datasheets/temp
  Using JRE_HOME:        /home/ebiztest/jdk1.6.0_34
  Using CLASSPATH:       /home/ebiztest/tomcat-datasheets/bin/bootstrap.jar:/home/ebiztest/tomcat-datasheets/bin/tomcat-juli.jar
  $
  </code></pre>
  
  <p>Control is returned immediately.</p>
  
  <p>Any ideas? Thanks!</p>
  
  <p><strong>In response to the answer from 'aa vv'</strong>
  Using commandResource instead of command let me point to a local file that contains the commands to run (added more commands for demonstration):</p>
  
  <pre><code>pwd
  . ~/.profile;java -version
  pwd
  java -version
  pwd
  cd ~/tomcat-datasheets/bin;pwd
  pwd
   ./startup.sh
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>start-tomcat:
    [sshexec] Connecting to servername:22
    [sshexec] cmd : pwd
    [sshexec] /home/ebiztest
    [sshexec] cmd : . ~/.profile;java -version
    [sshexec] java version "1.6.0_34"
    [sshexec]
    [sshexec] Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
    [sshexec]
    [sshexec] Java HotSpot(TM) Server VM (build 20.9-b04, mixed mode)
    [sshexec]
    [sshexec] cmd : pwd
    [sshexec] /home/ebiztest
    [sshexec] cmd : java -version
    [sshexec] java version "1.4.2_04"
    [sshexec]
    [sshexec] Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
    [sshexec] Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
    [sshexec]
    [sshexec] cmd : pwd
    [sshexec] /home/ebiztest
    [sshexec] cmd : cd ~/tomcat-datasheets/bin;pwd
    [sshexec] /home/ebiztest/tomcat-datasheets/bin
    [sshexec] cmd : pwd
    [sshexec] /home/ebiztest
    [sshexec] cmd :  ./startup.sh
    [sshexec] ksh: ./startup.sh:  not found
  </code></pre>
  
  <p>It seems commands on separate lines are run entirely separately from eachother, only semicolon separated commands on the same line execute sequentially. </p>