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
  • Please place that export CLASSPATH before the if. – Rui F Ribeiro Nov 17 '15 at 11:39
  • Is $BuildLabel being set in .bashrc or /home/test/blog/build.txt? Otherwise, the (new) if statement may fail. – Jeff Schaller Nov 17 '15 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). – Manu H Nov 17 '15 at 12:00
  • $BuildLabel is set in /home/test/blog/build.txt – Thiripu Nov 18 '15 at 5:59
  • Thanks, Rui F Ribeiro. Problem solved while placing CLASSPATH above if. – Thiripu Nov 19 '15 at 7:14
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.