8

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?

3 Answers 3

10

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
1
  • 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, 2016 at 2:50
7

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.

4

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .