This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Calling a Java Program through CRONTAB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling a Java Program through CRONTAB" Watch "Calling a Java Program through CRONTAB" New topic
Author

Calling a Java Program through CRONTAB

Vishnu Vardhan A N V
Greenhorn

Joined: Jul 25, 2003
Posts: 5
Hi,
I have a script which is excuted through a 'cron', in which I run a java program. But the program is not running in the cron. Is there any thing which we need to use to execute a JAVA program in a cron.
Regards
Vishnu
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Vishnu
Can you please provide your script or something to see how you are running the java program from the script?
Also, please explain- how do you know that your java program is not running?
Regards
Maulin
Vishnu Vardhan A N V
Greenhorn

Joined: Jul 25, 2003
Posts: 5
This is the script

cd /expbackup/ismspay/franchise/pihextraction
while :
do
java Payment
#Checking whether the file has any record at all
wc -l PIH_*.csv > a
i=`cut -c 1 a`
echo $i
if [ $i -ne 0 ]
then
cp PIH_*.csv /expbackup/ismspay/franchise/pihextraction/payready/.
cp PIH_*.log /expbackup/ismspay/franchise/pihextraction/paylog/.
rm -f PIH_*.csv
rm -f PIH_*.log
sh payftp.sh
mv /expbackup/ismspay/franchise/pihextraction/payready/PIH_*.csv /expbackup/ismspay/franchise/pihextraction/paydone/.
rm a
else
rm -f PIH_*.csv
rm -f PIH_*.log
rm a
fi
sleep 300
done

I find it not running because the action it is supposed to do is not being done. Is there any other way to monitor please let me know.
Regards
Vishnu
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

Hi Vishnu
Rule 1 about crontab: your path is not the same as if you had signed in. So in all probability your script does not know where the java executable is.
You can set the path, either in the script, or in the crontab entry (depending on the OS). However if this script is being run by root or a priveledged user, then this may open a security risk.
The recommended way in Unix is to specify the full path to the executable. Try typing 'which java' at the command prompt, to see exactly where your java executable is. Then put that full path into your script.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Yes. I agree with Andrew. Though I have never written a cron job myself
Try writing full path to java exe and see if it works.
Also, if I were you I would try writing a little separate program first instead testing on the real application.
Regards
Maulin
Vishnu Vardhan A N V
Greenhorn

Joined: Jul 25, 2003
Posts: 5
I have done what you had said and modified my script as follows.
#Executing the payment extraction program
export SHLIB_PATH=/oracle/app/oracle/product/8.1.7/lib
export LD_LIBRARY_PATH=/oracle/app/oracle/product/8.1.7/lib
JAVA_HOME=/opt/java1.2
CLASSPATH="$JAVA_HOME"/lib/tools.jar:/oracle/app/oracle/product/8.1.7/jdbc/lib/classes12.zip
export JAVA_HOME CLASSPATH
export ORACLE_HOME=/oracle/app/oracle/product/8.1.7
cd /expbackup/ismspay/franchise/pihextraction
echo $JAVA_HOME
echo $CLASSPATH
$JAVA_HOME/bin/java Vishnu
~
But even now when I run the script I am getting the following error
Exception in thread "main" java.lang.NoClassDefFoundError: Vishnu
But when I run the same class file in the command prompt, I am able to execute the same.
Chris De Vries
Ranch Hand

Joined: Dec 05, 2002
Posts: 65
Originally posted by Vishnu Vardhan A N V:
I have done what you had said and modified my script as follows.
#Executing the payment extraction program
JAVA_HOME=/opt/java1.2
CLASSPATH="$JAVA_HOME"/lib/tools.jar:/oracle/app/oracle/product/8.1.7/jdbc/lib/classes12.zip
export JAVA_HOME CLASSPATH


It looks like you have added tools.jar and oracle's classes to you CLASSPATH, but not the location of Vishnu.class. If you add that directory to your classpath it will probably work.
 
wood burning stoves
 
subject: Calling a Java Program through CRONTAB