11

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

Samiul
  • 485
  • 3
  • 7
  • 15
  • For some reason this was the top result for "crontab run until midnight" in google for me, so I'll add the answer for that here too, to run every minute from 6am until midnight you can't use `* 6-0 * * *`, it won't throw any errors and won't run, use `* 0,6-23 * * *` instead – Timo Huovinen Oct 21 '13 at 08:43
  • */3 06-23 * * 1-5 my-command This can help http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples – Adrian P. May 19 '17 at 19:50

1 Answers1

18

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
simon
  • 15,344
  • 5
  • 45
  • 67
  • i have written the following but giving bad hour when i try to save in cron tab . I have written */3 19-12 * * * mycommand path – Samiul Dec 07 '12 at 07:56
  • I want in a single command not two separate command – Samiul Dec 07 '12 at 08:05
  • that's not how cron works. you can simply kill the process at 11.30pm, if you like, but there is no way to tell cron to run a command for a specified period of time. if you think about it, it doesn't really make sense. – simon Dec 07 '12 at 08:07
  • every 3 minutes is working fine thats why i am not asking about the miniut. My problem in hour. As my cron should run daily from 7 pm to 11:30 am or 12 am in US time. Clear? – Samiul Dec 07 '12 at 08:08
  • ah - i think i see what you're asking for – simon Dec 07 '12 at 08:11
  • */3 19-12 * * * where is the error even following also giving error */3 19-12 * * mon-sat if i want to run my cron only in development working day (monday to saturday) – Samiul Dec 07 '12 at 08:14
  • i think we're on the same page now -- see edits :) – simon Dec 07 '12 at 08:15
  • */3 6-23 * * * my-command, its good but if i want evening 6pm to day 12 am then will it be */3 18-12 * * * my-command ? – Samiul Dec 07 '12 at 08:19
  • 12am is midnight. do you mean midnight or midday (12pm)? – simon Dec 07 '12 at 08:20
  • ## every three minutes between 6pm and midnight */3 6-23 * * * my-command The first one "## every three minutes between midnight and midday" is correct but this one "## every three minutes between 6pm and midnight" should be */3 16-23 * * * my-command Just confirm me Simon – Samiul Dec 07 '12 at 08:32
  • it should be 18 (6pm) :) – simon Dec 07 '12 at 08:39
  • ah! yes , it shout be 18 Thank you very much for giving me clue. Thank you boss. You save my time. :) – Samiul Dec 07 '12 at 08:42