aspose file tools*
The moose likes Linux / UNIX and the fly likes java program as cronjob in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "java program as cronjob in Linux" Watch "java program as cronjob in Linux" New topic
Author

java program as cronjob in Linux

Sangeetha Rao
Ranch Hand

Joined: Aug 01, 2005
Posts: 33
I have a problem with running a java program as cronjob. Here are the files:

Reminder.sh
-----------
export PATH=$PATH: (many path)
export CLASSPATH=$CLASSPATH: (many classpath)
echo 'classpath=' $CLASSPATH > /tmp/tmpfile
/usr/java/j2sdk1.4.2_09/bin/java com.wipro.innovation.scheduler.task.Reminder

Reminder.cronjob
----------------
30 17 ** * /home/com/wipro/innovation/scheduler/cron/Reminder.sh > /tmp/cronjob.log 2>&1

I have executed cronjob Reminder.cronjob to install the cronjob. I expect the Reminder java file to be run at 17:30 and /tmp/tmpfile and tmp/cronjob.log files to be created. But nothing is happening at 17:30. But when Reminder.sh is run manually, I am getting the expected result. What am I missing?
Sangeetha Rao
Ranch Hand

Joined: Aug 01, 2005
Posts: 33
A correction - I meant to say I executed "crontab /home/com/wipro/innovation/scheduler/cron/Reminder.cronjob" command to install the cronjob
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

try:

to see if the job has been installed.
If not, crontab -e will allow you to add/edit your jobs right there.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Well, first I'd make sure that crond (or whatever your system uses) is actually running. Get a simpler cron task to run. If you can't do that, then find out why.

Otherwise, if you can get some cron job to run, then things basically look OK here. Is Reminder.sh marked executable? I'm assuming that the script doesn't actually require anything to be in the inherited CLASSPATH, as when the cron job is run, it's likely to be undefined.


[Jess in Action][AskingGoodQuestions]
Sangeetha Rao
Ranch Hand

Joined: Aug 01, 2005
Posts: 33
Even a simple cron task is not running. Though I am able to see that task in the list when crontab -l is executed. What is the problem?
Sangeetha Rao
Ranch Hand

Joined: Aug 01, 2005
Posts: 33
Simple cron job is working now (I had given tabs instead of spaces in between the date fields in the cronjob syntax). But I am back to my initial problem now. Reminder.sh is getting executed manually but is not getting executed as cronjob. All the users of Reminder.sh have been given the write permission. What can go wrong this time?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

As I said, be sure Reminder.sh is executable (chmod +x Reminder.sh).

Are any error messages being mailed to the account that owns the cron job?

Now that you can run a simple job, is your fixed Java job at least writing those temp files that you were not seeing before?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program as cronjob in Linux