Cron job every day from 8AM to 8PM at 20 minutes interval

Braham Shakti picture Braham Shakti · Aug 6, 2014 · Viewed 9.3k times · Source

How to run cron job every day from 8:00 AM to 8:00 PM at 20 minutes interval eg cron job should start at 8:00 AM every day, then run at 8:20 AM then 8:40 AM then 9:00 AM up to 8:00 PM. Thanks.

EDIT: How to Implement it with ruby whenever gem.

Answer

fedorqui picture fedorqui · Aug 6, 2014

Just use two cronjobs:

*/20 8-19 * * * /your/script
0 20 * * * /your/script

That is:

  • one to run every 20 minutes from 8 to 19 hours
  • one to run at 20.00.

As a reminder, this is the format for a cronjob:

 +---------------- minute (0 - 59)
 |  +------------- hour (0 - 23)
 |  |  +---------- day of month (1 - 31)
 |  |  |  +------- month (1 - 12)
 |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
 |  |  |  |  |
 *  *  *  *  *  command to be executed