• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Calling a Java Program through CRONTAB

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic