It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "command to run a cron job" Watch "command to run a cron job" New topic
Author

command to run a cron job

chundottu jacob
Greenhorn

Joined: Mar 13, 2006
Posts: 7
Hi,
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.
Thanks
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: 800

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: 33
I've heard a lot of good things about Open Symphony's Quartz: http://www.opensymphony.com/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: 15952
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: command to run a cron job
 
Similar Threads
Cron job
Expect script on crontab
How to use Cron job with Java program?
stored procedure
auto call to servlet