Search code examples
macoscronmacos-mojave

Crontab not running properly on MacOS


I have set a crontab for a PHP script, which executes itself with no issues. My question is about the crontab; currently, I have this:

30,* 11 * * * php /Users/username/script.php >>/Users/username/script.log  2>/Users/username/script-error.log

With this crontab, I would expect the execution of the script every minute within 11:30 and 11:59. Instead, the script is being executed every minute within 11:00 and 11:59.

How can I set a crontab that allows me to run the script every minute within 11:30 an 11:59?

Thanks


Solution

  • The comma in 30,* acts as a separator for two values: the first value 30 and the second value *. As the second value (*) matches every minute, the script is executed every minute.

    What you want is a range, which you could specify with 30-59:

    30-59 11 * * * php /Users/username/script.php >>/Users/username/script.log  2>/Users/username/script-error.log