Configure Cronjob to run every 5 minutes, when it is between 5 and 20 hours
I need to make a setup for my cronjob
to work every 5 minutes. However, if the time of day is before 5
and greater than 20
I don't want it to run.
That is, I want a make a cron
that runs every 5 minutes, but only in the interval of 5 to 20 hours.
How can I do this?
Currently, I have a cron that like this:
0,30 * * * * php ~/pasta/para/app/artisan queue:work
What change should I make to make it work the way I want it to?
1 answers
*/5
means "any minute, but every 5".
Depending on the implementation, it suffices
*/5 5-20 * * * php ~/pasta/para/app/artisan queue:work
syntax from crontab :
* * * * * caminho/comando
│ │ │ │ │
│ │ │ │ └────── em quais dias da semana de 0 a 7 (tanto 0 quanto 7 são Domingo)
│ │ │ └────────── em quais meses (1 - 12)
│ │ └────────────── em quais dias (1 - 31)
│ └────────────────── em quais horas (0 - 23)
└────────────────────── em quais minutos (0 - 59)
Specifying each item:
* Todos
1,2,4 Um, dois e Quatro apenas
7-10 De 7 a 10, incluindo 8 e 9
*/5 A qualquer momento, mas com espaço de 5 (ex: 2,7,12,17...)
1-10/3 No intervalo de 1 a 10, mas de 3 em 3 (ex: 2,5,8)
Note: when you use /n
, It depends on when the cron
is updated by the table that the range is counted, so */5
can be both 0,5,10,15 and 1,6,11,16.
An example if it needed to be every 3 hours in that range:
*/5 5-20/3 * * * php ~/pasta/para/app/artisan queue:work
Note: cron
does not have intervals in some implementations (I do not know if this proceeds in some modern distro yet), you may need to specify all hours:
*/5 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 * * * php ~/pasta/para/app/artisan queue:work
More details in the crontab
manual: