I have OpenSuse Linux 12.3, and I have a script file that runs every half hour. I know it runs because it generates a log file. The log file as as follows: myscript.sh
I should say that this script runs fine from the command line. It also runs fine in Task Scheduler if I tell it to "run now", it does run, and does generate a log file, and the log file has the appropriate log data in it.
I did change the script to chmod 777, so everything has access to it. I know the cron service is running on the system. I can see log files being generated, but there is nothing in the log. They are 0 byte size files. This is when the Task Scheduler goes to run something.
So, again, here is the script: myscript.sh:
datestr=$(date +%Y%m%d_%H%M%S)
cd /home/tholmes/git/Tom_Utils/Tom_Utils
mvn exec:java -Dexec.mainClass="com.tom.test.utils.fix.MyJavaApp" -Dexec.args="12" > /home/tholmes/logs/my_java_app/12_$datestr.log
So, I do know that all the commands in this script work perfectly? When I run the script in the Task Scheduler manually, it works fine, and a log is generated. But when the Task Scheduler auto-runs, it doesn't run...
Can anyone help me what I did wrong? I did not expect this to be so difficult.
I found 3 other people who asked the same question, namely:
Why won't a cron job, which is executing a script, NOT execute specifically maven commands?
1) The first thing I did was download maven locally to my /opt/maven-3.2.3 directory. Normally, when I am developing my java code, maven is running from the built in maven within eclipse.
2) Within my script I added the exports to for JAVA_HOME, JRE_HOME, MAVEN_HOME as follows:
export JAVA_ROOT=/opt/java
export MAVEN_HOME=/opt/maven
export MAVEN_BINDIR=/opt/maven/bin
export JAVA_HOME=/opt/java
export JAVA_BINDIR=/opt/java/bin
export JRE_HOME=/opt/java/jre
export JRE_BINDIR=/opt/java/jre/bin
export PATH=${JAVA_HOME}:${JAVA_BINDIR}:$PATH
export PATH=${MAVEN_HOME}:${MAVEN_BINDIR}:$PATH
export PATH=${JRE_HOME}:${JRE_BINDIR}:$PATH
export PATH=${JAVA_HOME}:${JAVA_BINDIR}:$PATH
So, the path to java and maven were both setup within the script.
3) Finally, I made sure that I made sure that mvn was called from it's location (/opt/maven/bin), and this may have been overkill since the path was established, but I wanted to make sure the maven command was going to be executed from the correct location.
/opt/maven/bin/mvn exec:java -Dexec.mainClass="com.tom.test.utils.fix.MyJavaApp" -Dexec.args="12"
This solved my problem, and I hope this helps someone else. :-)