Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron with java

Status
Not open for further replies.

rhull

Programmer
May 23, 2001
46
US
My cron seems to do nothing

I have my crontab set up as follows
01 * * * * java /wic/local/bea/wls/BCP_email
(01 to test)

'java BCP_email' --> works fine

and when i save it writes to a tmp file
/tmp/crontab66onqa

Should it be saving to a tmp file?
also to invoke a java file is the crontab set up correctly?

-Thanks!
-R


 
The first lesson of using cron ...

When you run a job in cron, you must remember that there is no environment set up.

When you run the job yourself from the command line, you will have an environment set up (i.e. PATH, etc., usually from your .profile/.cshrc)

Chances are here that the cron job doesn't know where to look for the java command.

For starters, specify the full path to java in the cron job ...

1 * * * * /full/path/to/java /wic/local/bea/wls/BCP_email

(not sure what your 01 will do, try 1 instead)

If that doesn't work, then there may be other environment variables needed for java to work. If that's the case, it's best to write a shell script wrapper to run the job.

Greg.
 
As far as whether crontab should be saved to a tmp file, yes that's the default behaviour. You should find that the file is actually saved to the user's named account in /var/spool/cron/crontabs. HTH.
 
Thanks,I also needed to add all the .jar files to the classpath. My only other question is does it make a difference if I do it as root, or will it be fine under my login?

-R
 
Grega hinted at the possible implications above. Because cron has effectively no environment set, this needs to be explicitly set, possibly by executing the user's .profile (which should set PATHs etc) or by using the following construct:

su - <user> -c &quot;ksh <path to file to be executed>&quot;

The -c effectively transfers control of the process following to the <user> and associated environment. Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top