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