*
The moose likes Linux / UNIX and the fly likes Cron Script for StartUp 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 "Cron Script for StartUp" Watch "Cron Script for StartUp" New topic
Author

Cron Script for StartUp

Rahul Chaitanya
Greenhorn

Joined: Aug 22, 2010
Posts: 22
I had a Shell Script that executes a Java Jar file. I wanted to know a Cron Expression such that, my shell script should execute immediately and the script should be started automatically, even after a system reboot. Is there any cron tag that lets me to do this ?

We are using Linux OS.

Any help, will be appreciated.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

That's not what cron does; cron schedules a job to run at specific fixed times according to the system clock. What you want is a service.

Here is an article about them, but don't get too intimidated, because in reality, what almost everyone does is simply copy and modify one of the existing service scripts.


[Jess in Action][AskingGoodQuestions]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

As Ernest has said, cron isn't about running a script immediately, it's about running a script on a schedule.

Modern Linux distros have an implementation called "anacron" that can ensure that if the system was down when the scheduled time passed that the missed script(s) will run once the system is back up again, but that's as close you you can get using cron.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rahul Chaitanya
Greenhorn

Joined: Aug 22, 2010
Posts: 22
Thanks Ernest/Tim for your responses.

Actually, according to the deployment standards in my company, I shuold come up with some Cron expression to my script such that, it should start after the deployment (not required to be done immeadiately but after an hour or 2 hours and the deployment time is fixed).

I can write some cron expression to start at a particular time. But what I want is that, my script should should be picked up automatically even after a system restart. Is it possible to get this done with a Cron tag ?

Please, let me know.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Use cron to schedule regularly-repeated tasks.

Use "at" to schedule a delayed task for a single execution. I believe that "at" survives reboots just like anacron.

To schedule a task after a certain interval has expired, use "sleep" like so:


However, "sleep" doesn't survive reboot or even logout, so if you want something more durable with the same effect, you'll need to pair "at" with some datetime calculation.
 
wood burning stoves
 
subject: Cron Script for StartUp
 
Similar Threads
JDBC : java heap space exception
Calling a Java Program through CRONTAB
cron job
Struggling to run a script at regular intervals - any ideas?
Cron ta not working