stackUser
stackUser

Reputation: 579

Not able run the script based on the results of java program

I have a Java program that is populating data into xyz table and there is dataimporter script that is populating data from that xyz table to other tables.

I am trying to run the dataimporter only on the successful completion of Java Program.

Following is my script. The same kind of logic I am using at diff places and it's working fine. I tried echoing both $? and $retVal but don't see any echo statement result.

#!/bin/bash

//// ---code----

echo ".jar execution startd...currentMilliseconds"_$(date +%s%3N) >> ${LOGFILE} 2>&1
java -jar ./testservice-0.0.1-SNAPSHOT.jar ${ENV}  >> ${LOGFILE} 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
    echo "Error" >> ${LOGFILE} 2>&1
else
        echo "processing startd...currentMilliseconds"_$(date +%s%3N) >> ${LOGFILE} 2>&1
                bash -x ~/bin/DataImporter
        echo "processing completed...currentMilliseconds"_$(date +%s%3N) >> ${LOGFILE} 2>&1
fi

Could you please help to execute the DataImporter script on the successful completion of Java program completion? I am not able to see any if/else part output. Script is not logging any after java -jar command to investigate the issue. Java code is just stand-alone service processing via main function.

Upvotes: 0

Views: 26

Answers (1)

glenn jackman
glenn jackman

Reputation: 247072

It sounds like you may be using the shell's -e "errexit" option. Change your script to


# log everything
exec >> "$LOGFILE" 2>&1

echo ".jar execution startd...currentMilliseconds_$(date +%s%3N)"
if java -jar ./testservice-0.0.1-SNAPSHOT.jar "$ENV"; then
    echo "processing startd...currentMilliseconds_$(date +%s%3N)"
    bash -x ~/bin/DataImporter
    echo "processing completed...currentMilliseconds_$(date +%s%3N)"
else
    echo "Error"
fi

Upvotes: 1

Related Questions