• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java program as cronjob in Linux

 
Sangeetha Rao
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try:

to see if the job has been installed.
If not, crontab -e will allow you to add/edit your jobs right there.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sangeetha Rao
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic