File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a cron job from JAVA

 
Dhondiba Joshi
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to call a cron job from JAVA ?

any kind of help appreciated.
 
Dhondiba Joshi
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I meant how to run a java program from a cron job.Anybody ?

Thanks
 
Nandakumar Subramaniam
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a batch file or shell script executing the java class. Schedule the script in ur cron tab.

Sample of an entry in the crontab.
----------------------------------
# script to run the dashboard job
5,15,25,35,45,55 * * * * /usr/local/app/nps/scripts/runJob.sh


Sample of a shell script is given below:
----------------------------------------

#! /bin/bash

function alive() {
ps -eaf | grep -v grep | grep -c com.test.jobs.RunJob
}

if [ `alive` == 1 ]
then
pid_var=`ps -ef | grep com.test.job.RunJob | grep -v grep | awk '{print $2}'`
kill -9 $pid_var
fi

if [ `alive` == 0 ]
then
export LIBDIR=/usr/lpp/CommerceSuite/lib
export CLASSPATH=/usr/local/appupdates/digester:$LIBDIR/axis.jar:$LIBDIR/commons-logging.jar:$LIBDIR/jaxrpc.jar:$LIBDIR/commons-digester.jar:$LIBDIR/siemens.jar:$LIBDIR/AppInterfaceDevTools.jar:$LIBDIR/jconn2.jar:$LIBDIR/xerces.jar:$LIBDIR/xml4j.jar:$LIBDIR/activation.jar:$LIBDIR/mail.jar:$LIBDIR/NetComponents.jar:$LIBDIR/commons-collections.jar:$LIBDIR/commons-dbcp.jar:$LIBDIR/commons-pool.jar:$LIBDIR/log4j.jar:$LIBDIR/freetds_jdbc.snapshot.jar:/usr/local/lib/jar/db2java.zip:$LIBDIR/jms.jar:$LIBDIR/im q.jar:$LIBDIR/fscontext.jar:$LIBDIR/ibmjcefw.jar:$LIBDIR/ibmjceprovider.jar:$LIBDIR/wcsruntime.jar:$LIBDIR/commons-discovery.jar:$LIBDIR/saaj.jar:$LIBDIR/commons-beanutils.jar:$CLASSPATH
export PATH=/usr/java14/bin:$PATH
export JAVA_HOME=/usr/java14/
java com.test.job.populator.RunJob
fi


Hope this helps.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic