This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes calling a java standalone in crontab Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "calling a java standalone in crontab" Watch "calling a java standalone in crontab" New topic

calling a java standalone in crontab

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
I am trying to call a java standalone through the crontab. I have written a standalone java program and deployed ths same in /bin. I have written a file and i am calling the java file in that. contents are)
java Update

It works fine if I directly run the file from linux like ./

In my crontab i am calling the as

*/10 8-19 * * Mon-Fri /bin/ , which should run every 10 minutes from Monday to Friday. In this same way I have written a servlet(in place of standalone) which works fine.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

cron jobs don't have your full complement of environment variables available because they're not run in a login shell. Just make sure the includes everything it needs to run, and things should work fine -- i.e., path to Java, classpath, LD_LIBRARY_PATH, or whatever else you might need.

[Jess in Action][AskingGoodQuestions]
Don Morgan
Ranch Hand

Joined: Jul 24, 2003
Posts: 84
You can setup a common file with all the environment parameters you need and then source this file from within your shell script to properly set the environment. This is a neat and tidy way of keeping the environment definition in one place and works well if you need to have more than one program running with the same environment variables.

Don Morgan, Founder - FREE Audiobooks for Software Developers
Sarath PS

Joined: Oct 22, 2004
Posts: 11
try bash --login

Which will load all variables !
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You may need to include the following line at the top of your script:


This is typically needed to make a bash (or other shell) script run as a standalone command, even from the command prompt.


Java API Documentation
The Java Tutorial
kirti marode

Joined: May 02, 2006
Posts: 5
I am calling ajava program from a crontab, the entry is something like this

17 16 * * * $HOME/ >>$HOME/test.log 2>&1

where it shd execeute at specfic time and log the o/p of the program to test.log, I could see shellscript and program running but its not dumping the o/p to log file, why so ?
I agree. Here's the link:
subject: calling a java standalone in crontab
It's not a secret anymore!