Running a Cron job daily from 6 am to 11:30 pm

Samiul picture Samiul · Dec 7, 2012 · Viewed 33.8k times · Source

Could you help me please to run my cron job daily from 6 am to 11:30 pm in the following format

          • command path

Thanks

Answer

simon picture simon · Dec 7, 2012

cron can start jobs easily enough, but if you need to run something from 6am to 11.30pm, you'll need to issue a start command at 6am, and a stop command at 11.30pm.

something like this:

## start the job (6am)
  0  6 * * * /usr/bin/start-my-job

## stop the job (11.30pm)
 30 23 * * * /usr/bin/stop-my-job

edit: i think i see what you're asking for now. try this:

## every three minutes between 6am and 11.30pm
    */3  6-22 * * * my-command
 0-30/3    23 * * * my-command

edit: okay, if you want 6pm until midday the following day, you need:

## every three minutes between midnight and midday
  */3   0-11  * * * my-command
## every three minutes between 6pm and midnight
  */3  18-23  * * * my-command