How to run cron entry every 5 min during office hours only?

Hi

I need to setuop a cron entry to run every 5 min, only in office hours (between 8:00AM to 18:00PM, I did the following:

0,5,10,15,20,25,30,35,40,45,50,55 8,9,10,11,12,13,14,15,16,17,18 * * * /home/xxx/zzz.ksh

But somehow does not work.
Could it be wrong?

I reckon the hours field should be "8-17" so first run at 0800 and last at 1755.

Use a hypen to denote a range of hours.

---------- Post updated at 11:59 AM ---------- Previous update was at 11:54 AM ----------

Of course, that will run 7 days a week unless you specify a 'day of week' range instead of the *

1 Like

I have change now, waiting to see the results (my time in GMT +2)

Some cron servers also accept this syntax:-

*/5 8-17 * * * /your/command/here

This is the step from the zero of that item, so should be a factor of the maximum, e.g. 2, 3, 4, 6 or 12 for the hours. I can't see a neat way to do it every 10 minutes replacing 5,15,25,35,45,55 , although you could build it something like this:-

*/10 * * * * bash -c "/bin/sleep 300 ; /your/command/here"

The best place to check if your host supports it is the manual page for the file crontab.
Often this can be found with man 5 crontab but check with man -k crontab to get the various options for pages you can read, such as Unix.com man page for crontab file

I hope that this helps,
Robin

1 Like

the

*/5 * * * * /your/command/here

does not work on solaris 10 , only in linux

Don't forget, you should be using the 'crontab' command to enter cron jobs. If you're editing the crontab file directly yourself then cron may not know about the changes for up to 24 hours and therefore the job(s) won't run. Otherwise restart the cron daemon from the command line to alert it of the changes.

1 Like

I've found this document that suggests that it has an extension to allow this:-

5/10 * * * * /you/command/here

.... but there is no clue which variant this might be deployed in. It is rejected for me on CentOS 6 with this:-

crontab: installing new crontab
"/tmp/crontab.cVRcNc":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

It might be useful, but I'd prefer a fully functional external scheduler that allows for structured job planning and dependencies unless it's simple jobs running on many and widely distributed servers. Horses for courses I suppose. :stuck_out_tongue:

Robin

The /n stepping requires an interval

5-59/10 * * * * command

runs at 5,15,25,35,45,55

5-15/10 * * * * command

runs at 5,15

1 Like

be remind to re-activate your change on the crontab and verify with "crontab -l" to check on the change line is existing.