Ubuntu – Script not working through Cron – JDK version mismatch between shell and script


I am executing a script through cron using the below command:

*/10 * * * * cd  /nas/app/someFolder/psox; ./RunPSOX.sh >> /tmp/trial.log 2>&1

This is being executed by root user. All PATH and JAVA_HOME have been set at the root level and exported. JDK 1.6 is being used.

The script also has the PATH set inside it at the beginning (have tried both absolute and relative path), the JAVA_HOME and CLASSPATH too.
I have added the "env" and "java -version" into the script before the logic.

The script fails to work through cron but works when triggered manually.
The reason is that the jdk version at shell level is jdk 1.6 but when the script is executed through cron, it is picking up the jdk version as 1.4 and throws a Java error.
I have checked the associated property files and there is no reference of jdk 1.4 anywhere.

Please advise, where else I need to check for the jdk version and make it consistent as jdk 1.6 for both shell and the script when running through cron.

Best Answer

Related Question