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 command to run a 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 "command to run a cron job" Watch "command to run a cron job" New topic

command to run a cron job

chundottu jacob

Joined: Mar 13, 2006
Posts: 7
I am trying to set up a cron job via the Cron Job manager available in my CPanel. I have written a servlet that nedds to be executed as a cron job. Can anyone please tell me how to write the command for running this servlet? I know how to set the parameters related to the time,etc. The server company is using a Linux OS.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I do not believe this is possible, since a servlet's lifecyle is determined by the Servlet Container and cron only has access to the linux/unix environment.

It seems to me this type of job would be better suited for a regular Java program or some other type of executable.

But, if it is possible, I would be greatly interested.
Peter Rooke
Ranch Hand

Joined: Oct 21, 2004
Posts: 817

There's a API you may wish to look into, Daemon. Hope this helps.

Regards Pete
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
You might want to read into curl. It is a command line URL client. With it you can call pages.

curl http://myserver:8080/myapp/servlet/someservlet

You can then cron job it by

*/10 * * * * curl http://myserver:8080/myapp/servlet/someservlet

That will call the servlet every 10 minutes
Stian Almaas
Ranch Hand

Joined: Sep 22, 2005
Posts: 37
I've heard a lot of good things about Open Symphony's Quartz: . It is an open source job scheduler that can be run in an application server with your servlets. Every job is a Java class so you can do a lot of very cool stuff with it.
If you are going with cron then curl is a very easy solution to your problems, though.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

For a simple "touch" or basic data retrieval operation, you can also use cron to schedule executions of the wget (as in "web get") command.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: command to run a cron job
It's not a secret anymore!