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
14
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 Jun 28 '12 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 Jun 28 '12 at 16:57
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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