6

I want to set a cronjob entry that runs a script every 30 minutes from 9:00 to 18:00 but I do not want it to run at 18:30. The script should run for the first time at 9:00 and for the last time at 18:00. Is this possible?

1

2 Answers 2

13
0,30 9-18 * * * /path_to_script

However, the above will run at 18:30. So, you're best bet is to have a separate job to handle 18:00. So:

0,30 9-17 * * * /path_to_script
0 18 * * * /path_to_script

Also, Cron job generators are awesome.

2
  • This is a great answer!
    – dotancohen
    Commented Jun 28, 2012 at 16:48
  • I was wishing to accomplish this in a single line but I later learned that it was not possible only using cron. Thanks for your answer.
    – TestUser
    Commented Jun 28, 2012 at 16:57
2

Or do an extra test before firing the script. In the example below I test if current is less than 1815.

 0,30 9-18 * * * [ $(date +\%H\%M) -le 1815 ] && /path_to_script

You must log in to answer this question.

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