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

37,358

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
Share:
37,358
Samiul
Author by

Samiul

I am a software developer with 10 years experience in PHP and MYsql. I like to develop procedure in Mysql.Have interest on Python too.

Updated on December 07, 2020

Comments

  • Samiul
    Samiul over 3 years

    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
    Samiul over 11 years
    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
    Samiul over 11 years
    I want in a single command not two separate command
  • simon
    simon over 11 years
    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.
  • Samiul
    Samiul over 11 years
    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?
  • simon
    simon over 11 years
    ah - i think i see what you're asking for
  • Samiul
    Samiul over 11 years
    */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)
  • simon
    simon over 11 years
    i think we're on the same page now -- see edits :)
  • Samiul
    Samiul over 11 years
    */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 ?
  • simon
    simon over 11 years
    12am is midnight. do you mean midnight or midday (12pm)?
  • Samiul
    Samiul over 11 years
    ## 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
  • simon
    simon over 11 years
    it should be 18 (6pm) :)
  • Samiul
    Samiul over 11 years
    ah! yes , it shout be 18 Thank you very much for giving me clue. Thank you boss. You save my time. :)