Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to start cron job at 9:30 and then work every 5 minutes and then stop at 16:30 everday. Is this kind of scheduling possible in one or do I need two cron jobs?

share|improve this question
up vote 9 down vote accepted

I think something along the lines of:

30/5 9-16 * * *  /usr/bin/script_to_run.sh

See the wiki page for details of timing syntax. I suggest testing this with a script that logs the time it runs at to a file.

#!/bin/bash

echo "Cron ran at: " `date` >> /var/log/crontimetest.log
share|improve this answer
2  
i was surprised to see "30/5" used, so i looked at the cron source code, specifically entry.c, which parses each line of a crontab. in the function get_range(), it checks to see if the character after the first number (30 in this example) is a '-' or not. if it's not, the '/' is never seen. this is a bug; it ought to have printed a warning (or an error message) of the form, "'/' is only meaningful following a * or a n-m range". sorry folks! – Paul Vixie Jan 16 at 2:50

you'll need three crontab entries:

30-55/5 9 * * * /usr/bin/script-to-run.sh
*/5 10-15 * * * /usr/bin/script-to-run.sh
0-30/5 16 * * * /usr/bin/script-to-run.sh

please do not blame linux, or bsd, or me, for the bizarre and useless syntax of crontab entries. this was invented at AT&T Bell Labs, and later standardized as part of POSIX.

share|improve this answer

I think you need three jobs:

 */5 10-15 * * * yourjob
 0,5,10,15,20,25,30 16 * * * yourjob
 30,35,40,45,50,55 9 * * * yourjob
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.