Configure Cronjob to run every 5 minutes when it is between 5 to 20 hours

8

I need to make a setup so my cronjob works every 5 minutes. However, if the time of day is before 5 and greater than 20 I do not want it to run.

That is, I want to make a cron that runs every 5 minutes, but only in the range of 5 to 20 hours.

How can I do this?

Currently, I have a cron like so:

 0,30 * * * * php ~/pasta/para/app/artisan queue:work

What change should I make to it to work the way I want?

    
asked by anonymous 20.04.2016 / 20:04

1 answer

17

*/5 means "any minute, but every 5".

Depending on the implementation, this is enough

 */5 5-20 * * * php ~/pasta/para/app/artisan queue:work


crontab Syntax:

*   *   *   *   *       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 cron is updated by the table the range is counted, so */5 can be either 0.5, 10.15 as 1.6.111.16.

An example would need to be every 3 hours in that range:

 */5 5-20/3 * * * php ~/pasta/para/app/artisan queue:work

Note: cron has no breaks in some implementations (I'm not sure if this is in some modern distro yet), you may need to specify all the times:

*/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:

  

link

    
20.04.2016 / 20:06