1

Currently I have

*/5 * * * * (job) &

My goal is to run a crontab each 5 minutes after it finished executing, not every 5 minutes.

So what I want is

---- wait 5 minutes ---- run job ---- job finished ---- wait 5 minutes .... etc.

but currently it seems like

---- wait 5 minutes ---- run job ---- if 5 minutes passed run job again even if the previous job wasn't finished ---- wait 5 minutes .... etc.

which results in many concurrent threads that serve no purpose and make the system freeze.

  • This isn't what cron is meant for, so why use it at all? Just write a script that runs as a daemon and does `while true; do job; sleep 5m; done`. If you like, you can use cron's `@reboot` feature to start your script at boot time. – Nate Eldredge Jun 29 '20 at 22:49
  • @NateEldredge I followed https://unix.stackexchange.com/a/435407 - do I need the `@reboot` after `sudo systemctl enable mydaemon.service` – Maurice Beckmann Jun 29 '20 at 23:09
  • No, if you're setting up your daemon with `systemctl`, then you don't need to do anything at all with `cron`. – Nate Eldredge Jun 29 '20 at 23:19
  • @NateEldredge So following this tutorial, I am set and it does what I want? – Maurice Beckmann Jun 29 '20 at 23:21
  • It sounds like it. But you should test it, of course. – Nate Eldredge Jun 29 '20 at 23:23
  • @NateEldredge I just did. He forgot to `sudo chmod +x /usr/bin/mydaemon`. Otherwise it seems to work, rebooting now. After reboot, `ps -eo 'tty,pid,comm' | grep ^?` showed mydaemon. The script `/usr/bin/mydaemon` can also be executed by itself. Seems fine. The problem is, my job is kind of invisible, so it's rather hard to test it directly. Does this script of yours reoccur or does it run only once after boot? Ie is it an endless loop, as it should? – Maurice Beckmann Jun 29 '20 at 23:36

0 Answers0