• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Write a cron job to call struts action class

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to write a cron job in the Linux server that calls my foo.action class that has code that I want to run once in a day. How can I do that?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was the first entry in a Google Search for "crontab tutorial".
http://www.adminschoice.com/docs/crontab.htm

Combine this with the wget program and you should be able to do this in one line.
[ May 05, 2008: Message edited by: Ben Souther ]
 
Komal Khanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to call my struts action class from the crontab???
 
Komal Khanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would appreciate if someone can give small example on this.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Komal,
First let's figure out what you want to run. You could connect to the URL that calls your Struts action. You could call a Java class with a main method that calls your Struts action.

This means the first step is to come up with one line that runs what you want. It could be "java MyProgram" or a UNIX script/program. wget allows you to make a http connection which would connect to the URL.

Once you have that working, the link Ben provided shows how to set up a cron job.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in case there are people who missed the point:

You cannot "call a struts action class", via crontab or not. Struts is a web application framework, and struts action classes are defined in terms of that framework, so what you actually would need to to is invoke the framework.

Making a long story short, that means that you have to make a web request to the server containing a Struts app which employs the action class. You can use tools like wget or curl to do that. In fact, I'm in the process of setting up a cron job to pull in a morning newspaper (PDF) on a daily basis using that technique right now. It can be as simple as this:

wget -O /home/sales/dailyspecials.txt http://localhost/myapp/todaysspecials.do

(I hope the forum software didn't break that into 2 lines.)

One of the reasons why it's considered bad practice to put business logic into Struts action processors (or JSF backing beans) is exactly because you might want to be able to invoke those business functions outside of the original framework.

For those of your who Already Knew All This, I apologize. But I've discovered that enough people don't realize things like this have to be allowed for that I felt obliged to point it out explicitly.
 
Komal Khanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic