4

I want to run a script every 23 hours. following syntax tried but its not working. is it right syntax for 23 hours:

<cron_expr>0 0,23,46,69,92,115 * * *</cron_expr>
  • 2
    cronwtf.github.io – user2857 Jul 6 '15 at 9:55
  • 1
    No, the second number is the hour of the day. AFAIK what you want is not possible with cron expressions. – Fabian Schmengler Jul 6 '15 at 10:28
  • 1
    If you would explain why you need this and for what then maybe we can advise you any alternatives or give you alternative ideas. – 7ochem Jul 6 '15 at 10:41
6

You could do every 24 hours like this, every 23 hours would be a little trickier.

<cron_expr>0 23 * * *</cron_expr>

Technically the syntax for every something somethings would be */something, so */23 in your case.

Ie. If you wanted a cron to run every 6 hours, exactly on the hour, it would be,

<cron_expr>0 */6 * * *</cron_expr>

But this expression is only going to be valid for values under 12, as the cron's interpretation of 'every' resets each day.

So for every 23 hours, on the hour, you would be best executing it every hour like so, and doing a modulus of 23 within your script itself.

<cron_expr>0 * * * *</cron_expr>

Then in the method being executed, place this at the start,

$time = time();
if (((($time - ($time % 3600))/3600) % 23) != 0)
  return;
  • This will execute the job every day at 23:00, since 23 is the only hour of the day divisibly by 23 – Fabian Schmengler Jul 7 '15 at 12:47
  • That's why I gave a few examples and said technically. I can't say I've ever tried to run something on such an irregular schedule. – Ben Lessani - Sonassi Jul 7 '15 at 13:05
  • I've tested the behaviour of */23 and as suggested, it won't produce the desired results. So I've updated it with a complimentary PHP conditional statement. – Ben Lessani - Sonassi Jul 7 '15 at 22:21
-3

This is the correct way:

<cron_expr>* */23 * * *</cron_expr>
  • This will execute the job every day from 23:00 til 23:59 every minute. (23 is the only hour of the day divisibly by 23) – Fabian Schmengler Jul 6 '15 at 10:27
  • Why my answer is incorrect and the answer by Ben is correct.. i cant understand.. – nino.aratari Jul 7 '15 at 12:45
  • It is less wrong because of the 0 at the minute position, but also not correct. – Fabian Schmengler Jul 7 '15 at 12:47
  • my fault.. i didnt see the initiial zero in ben answer!!!! :) thx – nino.aratari Jul 7 '15 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.