Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cron Script for StartUp

 
Rahul Chaitanya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17987
47
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Chaitanya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17987
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic