• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run a Java application every hour automatically

 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all:
I need to run a Java application every hour
automatically. How to do it under Bourne/Korn
shell? Please point some books or website that
I can take a look if I have to write some
shell scripts or through some other ways.
Thanks in advance,
Sarah
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just an idea versus an answer for you. The way I would do it is write a C program that stays in an infinite while() loop. In the while loop you would create a new PThread in unix and execute the java application. Also, you would want to check for when that program has termintated and kill that PThread. Then, you can just set a timer, and do it every hour that way.
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cron jobs are the unix/linux flavour of job scheduling.
have a look at this link:
http://www.learninglinux.com/article.php?sid=57
Or do a google search for "cron job" for more info.
 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the reply.
I take a look of the websites that talk about
the cron job, but there is no one example
telling me how to use "crontab -e" to edit
the crontab file. I tried to use "crontab -e",
but can not get any clue. Please help!
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use crontab's editing facility, you need to set an environment variable called EDITOR, where EDITOR it an editing program like /usr/bin/vi (on Solaris, anyway) or /usr/dt/bin/dtpad (if you're using CDE's notepad tool).
This invocation will bring up the cron table for your account in the editing tool that you set, like so:
$ EDITOR=/usr/bin/vi
$ export EDITOR
$ crontab -e <user>
Of course, none of that tells you the file format that cron uses. For that, read the man page.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is what a crontab entry that mails a nagging messages to a user's webmail account looks like.
One thing to beware of is that the SYSTEM crontab format is somewhat different that USER crontabs. The example is a user crontab. For safety's sake, it's a good idea to use absolute file references, even though the example doesn't.
Cron is the recommended way to do this stuff because you don't have to do any "real" programming. I DON'T recommend writing a C program that does a poll-and-wait unless you really think that having a CPU usage of 100% means you're getting your money's worth :roll: There is a signal that can be used to allow a C program to sleep until an alloted time.
But a custom C program is really not the "Unix" way. If I were to choose one distinguishing philosphy that's virtually unique to Unix it would be that one never writes a custom app if it's possible to do the same with a string of one or more system tools.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic