This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to call a cron job from JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call a cron job from JAVA" Watch "How to call a cron job from JAVA" New topic
Author

How to call a cron job from JAVA

Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
How to call a cron job from JAVA ?

any kind of help appreciated.


SCJP,SCWCD
Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
Hi all,

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

Thanks
Nandakumar Subramaniam
Greenhorn

Joined: Aug 11, 2004
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a cron job from JAVA
 
Similar Threads
String format to create directory in Unix
stored procedure
How to use Cron job with Java program?
How to run a jsp continuously without loading it?
Web interface to delete folder