Job dependent on other job

Hi All

I am trying to run one command ie grep but I want it should execute only after the completion of a shell script has finished.

eg

Following is my script :

java -mx64m $JAVA_OPTS -Dant.home=$ANT_HOME -classpath $_CLASSPATH org.apache.tools.ant.Main -verbose -buildfile /opt/bea/wls
61/config/dev05/batch_automation/MBPSBatch/scripts/build.xml > /opt/bea/wls61/config/dev05/batch_automation/MassTransfer/lo
gs/ant.log 2>&1 &

grep -i "BUILD FAILED" /opt/bea/wls61/config/dev05/batch_automation/MassTransfer/logs/ant.log 2>/dev/null
rcode=$? ############save the return code here if Failed found it would be 0
if [ $? -ne 0 ]
then
echo "No failed found run the script abc.sh"
. /opt/bea/wls61/config/dev05/batch_automation/MassTransfer/startMassTransfer.sh
else
echo "Failed encounter ..."
mailx -s "[`date`] Failure: Error in script" sdfgg@dgssg.com < /opt/bea/wls61/config/dev05/batch_automation/Mass
Transfer/logs/ant.log
echo "Error was encountered in your script" | mailx -s "ALERT!!" dsfhjkhdfsjh@dsfjhl.com
fi

Problem is even though no BUILD FAILED is encountered in ant.log still else part gets executed ie Failed encounter.

Please suggest some ways so that it works on the logic....... if build success ,should process if part , if failure should execute else part

Thanks

Pankaj

You are submitting the "java -mx64m $JAVA_OPTS..." as a background job. I think if you keep it as a foreground process then grep will be executed only after the "java -mx64m $JAVA_OPTS..." thing.

Plz try and check.

~PG

You can do the following

#choice 1
java &
wait
grep 
#choice 2
java <.....> && grep <..> &
# choice  if the java build returns a meaningful status code
$(status=$(java <... > && echo "OKAY")  
if [[ $status = "OKAY" ]] ; then
   echo "Success"
else
   echo "failure"
fi ) &
wait

Can you check if your script failed atleast once? I mean you might be looking at the same old log file repeatedly. This is my guess. Try and let me know.

Just ues the "wait" command inside your shell script or from command line

ie

java -metc etc etc >.../log.file &
wait
grep BUILD...... /log.file

The wait will wait until the back ground process completes before allowing the next command to be executed...