Search code examples
phpcronexecute

Execute CRON 2 and 3 times per month?


I have following issue.
I need to run same script (with different args) in different 5 different dates.

  • 1x per month
  • 2x per month
  • 3x per month
  • 4x per month
  • every day

My current code:

1x month (run every month 1st day, 9:00)

0 9 1 * * php /script.php 1

2x month (need to setup cron)

? php /script.php 2

3x month (need to setup cron)

? php /script.php 3

4x month (run every Monday, 9:00)

0 9 * * 1 php /script.php 4

every day (run every day, 9:00)

0 9 * * * php /script.php e

Solution

  • Crontab help gives you the order of time values

    To define the time you can provide concrete values for minute (m), hour (h), day of month (dom), month (mon), and day of week (dow) or use '*'

    You did not specify any fixed day, so I'll put sample data for you.

    This cron will run every 1st and 15th at midnight

    0 0 1,15 * * /script.php 2
    

    This other every 1st,10th and 20th at midnight

    0 0 1,10,20 * * /script.php 3