LinuxQuestions.org
Help answer threads with 0 replies.
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, 05: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 06:19 AM.
 
Old 04-05-2016, 06:19 AM   #2
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,194

Rep: Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382
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, 07:07 AM   #3
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 583

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, 07:07 AM   #4
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,194

Rep: Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382Reputation: 1382
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, 07: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, 08:18 AM   #6
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 583

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, 08:19 AM   #7
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 583

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:37 AM
Backup script won't run in cron job. Why? Micro420 Linux - General 19 10-31-2007 09:26 PM
Script works when run manually but not in cron job Harlin Linux - Software 7 10-16-2007 07:36 PM
script does not run in cron job kashyapvirgo Linux - General 8 03-20-2007 11:55 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 12:21 PM

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

All times are GMT -5. The time now is 12:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration