File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes cron job Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "cron job" Watch "cron job" New topic

cron job

Prashanth Chandra
Ranch Hand

Joined: Dec 07, 2005
Posts: 79
I need to write a cron job script which automatically updates the values in the databse without anyone's intervention. I am pretty new to this concept and I have got no idea of how to write a script of cron job.

Thanks in advance
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Well a cron job is just like any other script except you call it from a cron file using the "crontab -e" command.

For example

*/10 * * * * /usr/local/bin/domything

will run the domything script every 10 minutes. The little asteriscs stand for minutes, hours, days, months and days of the week. A more detailed usage can be found here

After the asteriscs you can call anything and use semicolon ; to separate various commands.
Don Morgan
Ranch Hand

Joined: Jul 24, 2003
Posts: 84
Write your database update as a regular script (which, of course can call other java programs to actually to do the update or use something like isql) and then all you use cron for is to schedule the execution of that script. Once you have your script written, it is a simple step to add it to cron. Take a look at the man pages for cron or ask your sysadmin.
[ January 10, 2006: Message edited by: Don Morgan ]

Don Morgan, Founder - FREE Audiobooks for Software Developers
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The "script" does not have to be a shell script. It can be any executable program written in any language that you choose. cron just schedules when it should be run. I think you could make it as a Java application. The only caveat I can see is that cron might not like running something like "java MyApp", so you may need a shell script with just one line to launch your Java app.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: cron job
jQuery in Action, 3rd edition