It's not a secret anymore!
The moose likes Linux / UNIX and the fly likes Need help to schedule a job Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Need help to schedule a job" Watch "Need help to schedule a job" New topic

Need help to schedule a job

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I wrote a script which basically capture the necessary lines from the stack of a source file and dump them into a destination file. Now I am executing this script manually (using chmod command in the command line) to create the destination file. I am wondering if I can add some script in my existing script to execute this script automatically once a day (I mean to say I want to run a scheduler to execute this script automatically in stead of manually which I am doing now). I would appreciate if someone can help me writing this script as I am really new and do not have much knowledge in Unix script. Thank you.

Here is my script:
Peter Johnson

Joined: May 14, 2008
Posts: 5852

Try this: open a terminal and type:

Or try this: cron tutorial

JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17033

You don't need to "run a scheduler", since there's almost invariably a scheduler already running: cron, which as Peter pointed out, you can get more details on by using the "man" or "info" commands, looking at various websites, or consulting (The Linux Documentation Project).

Cron is good for regularly repeating things. For a one-off delayed execution of a command/script, there's also the "at" command.

Two things above and beyond the usual docs that you might want to take note of, though:

1. It's best to include the absolute path of the command that you want to execute in your crontab entry, not just a relative path or for that matter, assuming that your normal command-shell path will apply.

2. Cron runs in 2 different ways. Individual users can each schedule their own cron jobs, but there are also a set of directories for system-level cron tasks: /etc/cron.daily, /etc/cron.weekly, and so forth. These directories contain scripts (or links to scripts). When their respective intervals elapse, cron will scan the directory and for each item whose "executable" bit is set, execute that file. This process is controlled by the master crontab, which is /etc/crontab.

Also note that there is a small difference in formats between the system crontab and user crontabs. The system crontab includes a field that indicates what userid to run the scheduled command under. This isn't explained very well in the man page, I'm afraid.

Oh. One last thing, for what it's worth. Modern Linux systems understand that not all machines are running 24x7 (laptops, for example). So instead of vanilla cron, they often run a system named "anacron". Anacron will ensure that if the machine was powered off when a cron event should have run that the cron event should be taken care of when the system comes back up.

An IDE is no substitute for an Intelligent Developer.
Have you checked out Aspose?
subject: Need help to schedule a job
It's not a secret anymore!