-2

I have several fetch scripts that need to run, but I can't (and don't want to) run them all at once.

I would like to run each every 45 minutes, but not all at same time. Instead, with 1 minute offset each.

Bash script was declined, they can freeze and I want to run next one after minute even if the first one has freezed or is not yet finsihed.

I know */45 is every 45 minutes, but if I change first asteriks by values, like this:

0/45 *  * * *   root    /home/rrr/bash_devel/echo.sh
35/45 * * * *   root    /home/rrr/bash_devel/echo.sh
40/45 * * * *   root    /home/rrr/bash_devel/echo.sh

It does not seem to work.

Is there any way how to achive that? Or perhaps some better tool than CRON?

rRr
  • 370
  • 1
  • 5
  • 17
  • This might help: [How do set cron to run my script every 40mins/25mins?](https://stackoverflow.com/q/8181949/3776858) – Cyrus Jul 16 '17 at 22:04

2 Answers2

1

To run one script every 45 minutes:

 0  0-23/3 * * * root /home/rrr/bash_devel/echo.sh
45  0-23/3 * * * root /home/rrr/bash_devel/echo.sh
30  1-23/3 * * * root /home/rrr/bash_devel/echo.sh
15  2-23/3 * * * root /home/rrr/bash_devel/echo.sh
Cyrus
  • 84,225
  • 14
  • 89
  • 153
0

There's no way to do that with cron: there is no simple pattern of the first five fields that allows for "every 45 minutes".

You could have the job scripts run themselves every 45 minutes, and use cron just to kick them off. For example, if you created a script "repeatFourTimes.sh" that runs echo.sh, waits 45 minutes, then runs it again, waits, and runs it one last time, then your crontab could have lines like this:

1 */3 * * * repeatFourTimes.sh echo.sh
2 */3 * * * repeatFourTimes.sh echo.sh

So you'd get sequences like this:

12.01 cron runs repeatFourTimes, kicking off echo.sh immediately
12.02 cron runs repeatFourTimes, kicking off echo.sh immediately
12.46 first repeatFourTimes kicks off echo.sh again
12.47 second repeatFourTimes kicks off echo.sh again
13.31 first repeatFourTimes kicks off echo.sh again
13.32 second repeatFourTimes kicks off echo.sh again
14.16 first repeatFourTimes kicks off echo.sh again then finishes
14.17 second repeatFourTimes kicks off echo.sh again then finishes
15.01 cron runs repeatFourTimes, kicking off echo.sh immediately
15.02 cron runs repeatFourTimes, kicking off echo.sh immediately
...

Obviously far from ideal. For example, if the script crashes, you will likely miss out on a few hours of echo.sh. If you did the whole thing in cron, with four lines for each 3 hour cycle, then you'd avoid that risk at the cost of a much larger crontab.

Paul Hicks
  • 13,289
  • 5
  • 51
  • 78