0

I can't for the life of me wrap my head around cron notation. I've been playing around with crontab calculators for about 20 minutes trying to make it work out.

I need to run my task every 24 hours and 15 minutes. Can anyone help me figure this out?

Thanks!

Siri
  • 3
  • 2
  • This is impossible - how about every 24 hours? – Ed Heal Jan 26 '18 at 07:00
  • 1
    crontab is for executing tasks at time X (with some syntactic sugar for executing it every n whatever inside a time) not for executing tasks every 24*60+15 minutes for a sliding execution time – Patrick Artner Jan 26 '18 at 07:01
  • Ah bummer. What would you guys recommend? I was thinking I could run a script every minutes that keeps track of how much time has elapsed and once it hits 1455 minutes then it can run the real task... – Siri Jan 26 '18 at 07:03
  • Why the 16 minutes? – Ed Heal Jan 26 '18 at 07:06

1 Answers1

1

NO idea why you want this. Create a shell script:

  • Read a file
  • check the number stored in it
  • execute whatever if the counter % 97 == 0 or increment counter by 1
  • on execution you might want to reset your number to 0 as well
  • cron job that executes every 15 minutes and calls the script

If your server ever goes down you get a shift in your execution by the downtime occurred.

Have a read here: https://unix.stackexchange.com/a/10650 as well, they detail small Perl scripts with while true __something__ sleep and the watch approach as well as other methods.

@Edit as response to EdHeals comment:
This approach will have an additional sliding time due to 97 script executions a day - script execution time is quite fast (opening file, inspecting number, increment/null it + save file should be well below 1s) - still, its 97*x a day sliding time.

Cron executions may also slide, it only guarantee is that your job will start no sooner than the specified time.

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • 1
    This will slip as it does not take into account the amount of time to execute the script. – Ed Heal Jan 26 '18 at 07:24
  • @EdHeal agreed, and cron tab may slide it even more although that one does not accumulate. – Patrick Artner Jan 26 '18 at 08:02
  • 1
    I ended up making a time tracking python script that stores the last time the original script was run. Compare it with the last time, and if it is 24.25 hours later, run the original script again – Siri Jan 27 '18 at 20:19