0

The requirement is to run a cron on an hourly/daily basis.

But sometimes, the cron takes too long to complete before the subsequent execution.

So, when the subsequent execution starts, it shouldn't run 2 parallel jobs.

Instead, it is supposed to kill the already executing job & start a new one.

I tried the following but nothing worked.

  1. pkill & run my script in cron - this, this & this
  2. pgrep & kill instead of pkill in above solution - a one-liner bash using && & ;
  3. run-one & run-this-one also in it.

What's the best way to do it?

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86

1 Answers1

0

timeout

* * * * * /usr/bin/timeout 59 /home/script.sh

The above cron runs every minute but the execution terminates after 59 seconds(if it has not finished).

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86