shell script over SSH ends unexpectedly after running 'ant build'

Posted by YShin on Super User See other posts from Super User or by YShin
Published on 2014-08-23T02:49:31Z Indexed on 2014/08/23 4:22 UTC
Read the original article Hit count: 610

Filed under:
|
|

I wrote a shell script that runs on remote host to build source code with 'ant build' command, and then distribute the built binary to other servers.

However, right after Ant build is over successfully(I can see the command line output saying Build was successful), the ssh session ends and whatever commands after 'ant build' does not get executed.

I'm confused what might be cause of this behavior. I suspected that it might be because the 'ant build' command takes too long time, and SSH somehow quits itself after that long command. But I don't think that's correct since if I just do 'sleep 60' in place of 'ant build' command, it actually execute latter commands as intended.

I'm new at shell programming, so I might have made some silly misassumption. Can someone provide a pointer to a possible cause of this problem?

My shell script

#!/bin/bash
# Inject some variables

ssh -T $SSH_USER@$SSH_URL "setenv REMOTE_BASE_DIR $REMOTE_BASE_DIR; setenv CASSANDRA_SRC_TAR_FILE $CASSANDRA_SRC_TAR_FILE; setenv CASSANDRA_SRC_DIR_NAME $CASSANDRA_SRC_DIR_NAME; setenv CLUSTER_SIZE $CLUSTER_SIZE; setenv REMOTE_REDEPLOY_SCRIPT $REMOTE_REDEPLOY_SCRIPT; /bin/bash" << 'EOF'

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0

cd $REMOTE_BASE_DIR/$CASSANDRA_SRC_DIR_NAME

echo "## Building Cassandra source"
ant clean build

# Anything after this doesn't run
echo "## Ant Build is over. Invoking redeploy script on remote nodes"

# Invoke redeploy script for each node
for (( i=0; i < CLUSTER_SIZE; i++))
do
echo "## Invoking redeploy script on node-$i"

done

Command-line output

## Building Cassandra source
Buildfile: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build.xml

clean:
   [delete] Deleting directory /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/test
   [delete] Deleting directory /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes
   [delete] Deleting directory /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/gen-java
   [delete] Deleting directory /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/resources/org/apache/cassandra/config

init:
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes/main
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes/thrift
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/test/lib
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/test/classes
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/gen-java

maven-ant-tasks-localrepo:

maven-ant-tasks-download:

maven-ant-tasks-init:

maven-declare-dependencies:

maven-ant-tasks-retrieve-build:

init-dependencies:
     [echo] Loading dependency paths from file: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/build-dependencies.xml

check-gen-cli-grammar:

gen-cli-grammar:
     [echo] Building Grammar /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/java/org/apache/cassandra/cli/Cli.g  ....

check-gen-cql2-grammar:

gen-cql2-grammar:
     [echo] Building Grammar /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/java/org/apache/cassandra/cql/Cql.g  ...

check-gen-cql3-grammar:

gen-cql3-grammar:
     [echo] Building Grammar /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/java/org/apache/cassandra/cql3/Cql.g  ...

build-project:
     [echo] apache-cassandra: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build.xml
    [javac] Compiling 43 source files to /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes/thrift
    [javac] Note: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] Compiling 865 source files to /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes/main
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

createVersionPropFile:
    [mkdir] Created dir: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/resources/org/apache/cassandra/config
[propertyfile] Creating new property file: /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/src/resources/org/apache/cassandra/config/version.properties
     [copy] Copying 3 files to /scratch/ISS/shin14/repos/apache-cassandra-2.0.8-src-0713/build/classes/main

build:

BUILD SUCCESSFUL
Total time: 32 seconds

© Super User or respective owner

Related posts about bash

Related posts about ssh