1

I run a script file through CRON daily which involves running selenium testcases and sending the report as mail. Here is my script: check.sh

#!/bin/sh
set -x
./.bashrc
export CLASSPATH=/home/test/TestAutomation/lib/*:.
cd /home/test/TestAutomation/lib/
/usr/bin/java -jar selenium-server.jar & 
cd
javac Api.java
java Api 
cd /home/test/TestAutomation/selenium/reports/
cp result.html /home/test/TestReports
sh /home/test/repgen.sh
sleep 30
sh /home/test/masRepgen.sh

This script works fine in cron. In this, sh /home/test/masRepgen.sh this script compiles and executes java file and Send Mail. I made a small change to the above script as follows.

#!/bin/sh
set -x
./.bashrc
. /home/test/blog/build.txt
cd /home/test/VT/CT/
if  [ -e /home/test/VT/CT/CT__$BuildLabel ]; then
echo "Testcases has been run already"
else
export CLASSPATH=/home/test/TestAutomation/lib/*:.
cd /home/test/TestAutomation/lib/
/usr/bin/java -jar selenium-server.jar & 
cd
javac Api.java
java Api 
cd /home/test/TestAutomation/selenium/reports/
cp result.html /home/test/TestReports
sh /home/test/repgen.sh
sleep 30
fi
sh /home/test/masRepgen.sh

After this change, I'm not receiving mail. ie., sh /home/test/masRepgen.sh doesn't compiling java class. I couldn't identify where the error is.

masRepgen.sh contains this.

cd /home/test/
/home/test/jdk1.7.0_12/bin/javac SendMail.java
/home/test/jdk1.7.0_12/bin/java SendMail "http://172.20.8.50/Regression/CR__$BuildLabel/compareresults_index.html" "http://172.20.8.50/Summary__$BuildLabel/complete_summary.html"

I added this in crontab:

45 02 * * * /bin/sh check.sh >> UI.txt
5
  • Please place that export CLASSPATH before the if. Commented Nov 17, 2015 at 11:39
  • Is $BuildLabel being set in .bashrc or /home/test/blog/build.txt? Otherwise, the (new) if statement may fail. Commented Nov 17, 2015 at 11:57
  • you may post the relevants lines of your crontab or anacrontab and add precisions about the user executing this script (I assume this is the user test as you cd into /home/test/ but this is not obvious). Commented Nov 17, 2015 at 12:00
  • $BuildLabel is set in /home/test/blog/build.txt Commented Nov 18, 2015 at 5:59
  • Thanks, Rui F Ribeiro. Problem solved while placing CLASSPATH above if. Commented Nov 19, 2015 at 7:14

1 Answer 1

1

By placing export CLASSPATH=/home/test/TestAutomation/lib/*:. above if condition solves the problem. Thanks everyone for the comments.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.