Cron job to run every minute from 11PM to 6AM

cron

I have a python program which I need to run every minute from 11PM (EDT) to 06AM (EDT). How can I schedule a cron job to do this?

* 23-6 * * 1-5 python my_program.py

will this work? or do I have to write 2 separate cron jobs for this?

Best Answer

Ranges that wrap around like that are ambiguous. Specify the hours as 23,0-6 instead and avoid future problems.

Cron checks every minute the contents of crontab files and if it founds coincidence of the time and the conditions it will run the script indicated on the line.

For this case these is the set of coincidences that must be met:

  • From 11 PM to 11:59 PM and from 0:00 to 6:59 AM
  • From monday to friday

So, every minute during the time that the set of coincidences are true, it will run.

Don't expect it to run outside of the range of hours and days indicated, for example on saturday.

Related Question