LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2016, 04:53 AM   #1
eisa123
LQ Newbie
 
Registered: Apr 2016
Posts: 2

Rep: Reputation: Disabled
Cron job that calls ksh Script to run java in AIX


Hi,

I have written a cron job that get executes everyday 10AM and call the ksh script but that ksh script shows echo but doesnot run java program, though when i run the same script manually it works fine and calls java program.Please help me urgently.

I am running the cronjob from folder /data02/Cognos10/sdk/java/CXOSrc/
which has run.sh and CXOJob java and class files.

Cron Job -
#!/usr/bin/ksh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/data02/Cognos10/sdk/java/CXOSrc/

0 10 * * * /data02/Cognos10/sdk/java/CXOSrc/run.sh > /tmp/cron.log


run.sh

#!/usr/bin/ksh

export CRN_HOME=/data02/Cognos10

export JAVA_HOME=/usr/java71_64

export JAVA=$JAVA_HOME/bin/java

export JAR_HOME=$CRN_HOME/sdk/java/lib

echo $CRN_HOME

export CLASSPATH=$CLASSPATH:../Common:../HandlersCS:../Security:../ReportParams:../ReportSpec:../ViewCMReports:../ViewCMPackages:../log4j.properties:../ExecReports:../runreport:../Scheduler:../ContentStoreExplorer:/data02/Cognos10/sdk/java/lib/activation.jar:/data02/Cognos10/sdk/java/lib/axis.jar:/data02/Cognos10/sdk/java/lib/axisCognosClient.jar:/data02/Cognos10/sdk/java/lib/commons-discovery-0.2.jar:/data02/Cognos10/sdk/java/lib/commons-logging-1.1.jar:/data02/Cognos10/sdk/java/lib/commons-logging-adapters-1.1.jar:/data02/Cognos10/sdk/java/lib/commons-logging-api-1.1.jar:/data02/Cognos10/sdk/java/lib/dom4j-1.6.1.jar:/data02/Cognos10/sdk/java/lib/jaxen-1.1.1.jar:/data02/Cognos10/sdk/java/lib/jaxrpc.jar:/data02/Cognos10/sdk/java/lib/mail.jar:/data02/Cognos10/sdk/java/lib/saaj.jar:/data02/Cognos10/sdk/java/lib/wsdl4j-1.5.1.jar:/data02/Cognos10/sdk/java/lib/log4j-1.2.17.jar


echo $CLASSPATH

$JAVA -classpath "$CLASSPATH" CXOJob

Last edited by eisa123; 04-05-2016 at 05:19 AM.
 
Old 04-05-2016, 05:19 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,591

Rep: Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689
Quote:
Originally Posted by eisa123 View Post
Hi,

I have written a cron job that get executes everyday 10AM and call the ksh script but that ksh script shows echo but doesnot run java program, though when i run the same script manually it works fine and calls java program.Please help me urgently.

I am running the cronjob from folder /data02/Cognos10/sdk/java/CXOSrc/
which has run.sh and CXOJob java and class files.

Cron Job -
#!/usr/bin/ksh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/data02/Cognos10/sdk/java/CXOSrc/

0 10 * * * /data02/Cognos10/sdk/java/CXOSrc/run.sh > /tmp/cron.log


run.sh

#!/usr/bin/ksh

export CRN_HOME=/data02/Cognos10

export JAVA_HOME=/usr/java71_64

export JAVA=$JAVA_HOME/bin/java

export JAR_HOME=$CRN_HOME/sdk/java/lib

echo $CRN_HOME

export CLASSPATH=$CLASSPATH:../Common:../HandlersCS:../Security:../ReportParams:../ReportSpec:../ViewCMReports:../ViewCMPackages::../log4j.properties:../ExecReports:../runreport:../Scheduler:../ContentStoreExplorer:/data02/Cognos10/sdk/java/lib/activation.jar:/data02/Cognos10/sdk/java/lib/axis.jar:/data02/Cognos10/sdk/java/lib/axisCognosClient.jar:/data02/Cognos10/sdk/java/lib/commons-discovery-0.2.jar:/data02/Cognos10/sdk/java/lib/commons-logging-1.1.jar:/data02/Cognos10/sdk/java/lib/commons-logging-adapters-1.1.jar:/data02/Cognos10/sdk/java/lib/commons-logging-api-1.1.jar:/data02/Cognos10/sdk/java/lib/dom4j-1.6.1.jar:/data02/Cognos10/sdk/java/lib/jaxen-1.1.1.jar:/data02/Cognos10/sdk/java/lib/jaxrpc.jar:/data02/Cognos10/sdk/java/lib/mail.jar:/data02/Cognos10/sdk/java/lib/saaj.jar:/data02/Cognos10/sdk/java/lib/wsdl4j-1.5.1.jar:/data02/Cognos10/sdk/java/lib/log4j-1.2.17.jar


echo $CLASSPATH

$JAVA -classpath "$CLASSPATH" CXOJob
Note that in the above you use the command $JAVA but have never SET the variable JAVA in the script. If JAVA is not set, that line starts the command
Code:
-classpath
with parameters. Most unlikely to do anything.
 
Old 04-05-2016, 06:07 AM   #3
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
I am pretty sure I can see a "export JAVA=$JAVA_HOME/bin/java" in the script text.

@OP, you have 2 echo:
Code:
echo $CRN_HOME

...

echo $CLASSPATH
are the outputs of both displayed in the log file?
 
Old 04-06-2016, 06:07 AM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,591

Rep: Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689
Correction welcomed.

Quote:
Originally Posted by ilesterg View Post
I am pretty sure I can see a "export JAVA=$JAVA_HOME/bin/java" in the script text.
On second reading I see that. Missed it the first time. Thank you.

It may help to echo each environment variable to the log just before the command. That will allow you to double check the log against what you see on disk to ensure that it comes out correct.
 
Old 04-07-2016, 06:27 AM   #5
eisa123
LQ Newbie
 
Registered: Apr 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
I am able to fix the issue, gave absolute path.Cron was not recognizing relative url's, though created from same folder.Thanks.
 
Old 04-07-2016, 07:18 AM   #6
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
Ooops. Totally missed that.

This would work too:
Code:
...
echo $CLASSPATH

$JAVA -classpath "$CLASSPATH" $CRN_HOME/sdk/java/CXOSrc/CXOJob
...
 
Old 04-07-2016, 07:19 AM   #7
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
You can also mark this thread as solved once you are satisfied.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] run cp script as batch or cron job bugrake Linux - Newbie 5 11-29-2013 10:37 AM
Backup script won't run in cron job. Why? Micro420 Linux - General 19 10-31-2007 08:26 PM
Script works when run manually but not in cron job Harlin Linux - Software 7 10-16-2007 06:36 PM
script does not run in cron job kashyapvirgo Linux - General 8 03-20-2007 10:55 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration